30 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
import grpc
 | 
						|
import BeiHangGrpc_pb2_grpc, BeiHangGrpc_pb2
 | 
						|
 | 
						|
 | 
						|
 | 
						|
def helmet_test(ip, pic_url):
 | 
						|
    channel = grpc.insecure_channel(ip)      # 监听频道
 | 
						|
    stub = BeiHangGrpc_pb2_grpc.Helmet_RegStub(channel)   # 客户端使用Stub类发送请求,参数为频道,为了绑定链接
 | 
						|
    image_id = 3
 | 
						|
 | 
						|
    # 本地图像输入
 | 
						|
    # image_path = "./onnx/image/single3.jpg"
 | 
						|
    # with open(image_path, 'rb') as f:
 | 
						|
    #      image_base64 = str(base64.b64encode(f.read()), encoding='utf-8')
 | 
						|
    # request = BeiHangGrpc_pb2.JinYu_Request(zzid=image_id,imgsbase64=image_base64)
 | 
						|
 | 
						|
    request = BeiHangGrpc_pb2.JinYu_Request(zzid=image_id, imgUrl=pic_url)
 | 
						|
    try:
 | 
						|
        response = stub.sendHelmet_Info(request)
 | 
						|
        print("network success! \n")
 | 
						|
        print(response.helmetinfoList[0].head_helmet)
 | 
						|
    except Exception:
 | 
						|
        print("network error! \n")
 | 
						|
 | 
						|
 | 
						|
if __name__ == "__main__":
 | 
						|
    helmet_test(
 | 
						|
        ip='122.224.229.24:2000',
 | 
						|
        pic_url='http://1.203.161.103:2800/media/2022/07/06/dsf_bf6446cc-f9cd-11ec-bd2d-e4246c7d1635_34597240_34614457.jpg')
 |