37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
|
|
import grpc
|
|
import BeiHangGrpc_pb2_grpc
|
|
import BeiHangGrpc_pb2
|
|
|
|
|
|
def helmet(ip: str, pic_url: str):
|
|
"""安全帽事件
|
|
|
|
Args:
|
|
ip (_type_): _description_
|
|
pic_url (_type_): _description_
|
|
"""
|
|
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)
|
|
response = stub.sendHelmet_Info(request)
|
|
if response.helmetinfoList:
|
|
for i in response.helmetinfoList:
|
|
if i.head_helmet == 0:
|
|
return True, response
|
|
return False, response
|
|
|
|
|
|
if __name__ == "__main__":
|
|
helmet(
|
|
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')
|