算法优化一下
This commit is contained in:
parent
9aeb2510a9
commit
19cbd6dd2a
|
@ -36,9 +36,7 @@ def helmet(ip: str, pic_url: str):
|
||||||
stub = BeiHangGrpc_pb2_grpc.Helmet_RegStub(
|
stub = BeiHangGrpc_pb2_grpc.Helmet_RegStub(
|
||||||
channel) # 客户端使用Stub类发送请求,参数为频道,为了绑定链接
|
channel) # 客户端使用Stub类发送请求,参数为频道,为了绑定链接
|
||||||
image_id = 1
|
image_id = 1
|
||||||
img_path = save_dahua_pic(pic_url)
|
request = BeiHangGrpc_pb2.JinYu_Request(zzid=image_id, imgUrl=pic_url)
|
||||||
request = BeiHangGrpc_pb2.JinYu_Request(
|
|
||||||
zzid=image_id, imgUrl=settings.BASE_URL_OUT + img_path)
|
|
||||||
response = stub.sendHelmet_Info(request)
|
response = stub.sendHelmet_Info(request)
|
||||||
if response.helmetinfoList:
|
if response.helmetinfoList:
|
||||||
for i in response.helmetinfoList:
|
for i in response.helmetinfoList:
|
||||||
|
@ -58,11 +56,8 @@ def helmet2(ip: str, pic_url: str):
|
||||||
stub = BeiHangGrpc_pb2_grpc.Helmet_RegStub(
|
stub = BeiHangGrpc_pb2_grpc.Helmet_RegStub(
|
||||||
channel) # 客户端使用Stub类发送请求,参数为频道,为了绑定链接
|
channel) # 客户端使用Stub类发送请求,参数为频道,为了绑定链接
|
||||||
image_id = 2
|
image_id = 2
|
||||||
img_path = save_dahua_pic(pic_url)
|
request = BeiHangGrpc_pb2.JinYu_Request(zzid=image_id, imgUrl=pic_url)
|
||||||
request = BeiHangGrpc_pb2.JinYu_Request(
|
|
||||||
zzid=image_id, imgUrl=settings.BASE_URL_OUT + img_path)
|
|
||||||
response = stub.sendHelmet_Info(request)
|
response = stub.sendHelmet_Info(request)
|
||||||
os.remove(settings.BASE_DIR + img_path)
|
|
||||||
if response.helmetinfoList:
|
if response.helmetinfoList:
|
||||||
for i in response.helmetinfoList:
|
for i in response.helmetinfoList:
|
||||||
if i.head_helmet == 1: # 未戴安全帽事件成立
|
if i.head_helmet == 1: # 未戴安全帽事件成立
|
||||||
|
@ -75,15 +70,12 @@ def fire1(ip: str, pic_url: str):
|
||||||
channel = grpc.insecure_channel(ip+':2001')
|
channel = grpc.insecure_channel(ip+':2001')
|
||||||
stub = BeiHangGrpc_pb2_grpc.Fire_RegStub(channel)
|
stub = BeiHangGrpc_pb2_grpc.Fire_RegStub(channel)
|
||||||
image_id = 3
|
image_id = 3
|
||||||
img_path = save_dahua_pic(pic_url)
|
|
||||||
# img = cv2.imread(img_path)
|
# img = cv2.imread(img_path)
|
||||||
# resized_img = cv2.resize(img, None, fx=0.25, fy=0.25)
|
# resized_img = cv2.resize(img, None, fx=0.25, fy=0.25)
|
||||||
# resized_img = cv2.imencode('.png', resized_img)[1]
|
# resized_img = cv2.imencode('.png', resized_img)[1]
|
||||||
# image_base64 = str(base64.b64encode(resized_img))[2:-1]
|
# image_base64 = str(base64.b64encode(resized_img))[2:-1]
|
||||||
request = BeiHangGrpc_pb2.JinYu_Request(
|
request = BeiHangGrpc_pb2.JinYu_Request(zzid=image_id, imgUrl=pic_url)
|
||||||
zzid=image_id, imgUrl=settings.BASE_URL_OUT + img_path)
|
|
||||||
response = stub.sendFire_Info(request)
|
response = stub.sendFire_Info(request)
|
||||||
os.remove(settings.BASE_DIR + img_path) # 删除临时图片
|
|
||||||
if response.FireinfoList:
|
if response.FireinfoList:
|
||||||
for i in response.FireinfoList:
|
for i in response.FireinfoList:
|
||||||
if i.fire == 0: # 配置了灭火器
|
if i.fire == 0: # 配置了灭火器
|
||||||
|
@ -96,11 +88,8 @@ def fangtang(ip: str, pic_url: str):
|
||||||
channel = grpc.insecure_channel(ip+':2003')
|
channel = grpc.insecure_channel(ip+':2003')
|
||||||
stub = BeiHangGrpc_pb2_grpc.FA_RegStub(channel)
|
stub = BeiHangGrpc_pb2_grpc.FA_RegStub(channel)
|
||||||
image_id = 4
|
image_id = 4
|
||||||
img_path = save_dahua_pic(pic_url)
|
request = BeiHangGrpc_pb2.JinYu_Request(zzid=image_id, imgUrl=pic_url)
|
||||||
request = BeiHangGrpc_pb2.JinYu_Request(
|
|
||||||
zzid=image_id, imgUrl=settings.BASE_URL_OUT + img_path)
|
|
||||||
response = stub.sendFire_Info(request)
|
response = stub.sendFire_Info(request)
|
||||||
os.remove(settings.BASE_DIR + img_path) # 删除临时图片
|
|
||||||
if response.FAinfo == False:
|
if response.FAinfo == False:
|
||||||
return True, response
|
return True, response
|
||||||
return False, response
|
return False, response
|
||||||
|
@ -111,11 +100,8 @@ def jingjiedai(ip: str, pic_url: str):
|
||||||
channel = grpc.insecure_channel(ip+':2001')
|
channel = grpc.insecure_channel(ip+':2001')
|
||||||
stub = BeiHangGrpc_pb2_grpc.Fire_RegStub(channel)
|
stub = BeiHangGrpc_pb2_grpc.Fire_RegStub(channel)
|
||||||
image_id = 3
|
image_id = 3
|
||||||
img_path = save_dahua_pic(pic_url)
|
request = BeiHangGrpc_pb2.JinYu_Request(zzid=image_id, imgUrl=pic_url)
|
||||||
request = BeiHangGrpc_pb2.JinYu_Request(
|
|
||||||
zzid=image_id, imgUrl=settings.BASE_URL_OUT + img_path)
|
|
||||||
response = stub.sendFire_Info(request)
|
response = stub.sendFire_Info(request)
|
||||||
os.remove(settings.BASE_DIR + img_path) # 删除临时图片
|
|
||||||
if response.FireinfoList:
|
if response.FireinfoList:
|
||||||
for i in response.FireinfoList:
|
for i in response.FireinfoList:
|
||||||
if i.fire == 2: # 配置了警戒带
|
if i.fire == 2: # 配置了警戒带
|
||||||
|
@ -128,11 +114,8 @@ def qiping(ip: str, pic_url: str):
|
||||||
channel = grpc.insecure_channel(ip+':2001')
|
channel = grpc.insecure_channel(ip+':2001')
|
||||||
stub = BeiHangGrpc_pb2_grpc.Fire_RegStub(channel)
|
stub = BeiHangGrpc_pb2_grpc.Fire_RegStub(channel)
|
||||||
image_id = 3
|
image_id = 3
|
||||||
img_path = save_dahua_pic(pic_url)
|
request = BeiHangGrpc_pb2.JinYu_Request(zzid=image_id, imgUrl=pic_url)
|
||||||
request = BeiHangGrpc_pb2.JinYu_Request(
|
|
||||||
zzid=image_id, imgUrl=settings.BASE_URL_OUT + img_path)
|
|
||||||
response = stub.sendFire_Info(request)
|
response = stub.sendFire_Info(request)
|
||||||
os.remove(settings.BASE_DIR + img_path) # 删除临时图片
|
|
||||||
if response.FireinfoList:
|
if response.FireinfoList:
|
||||||
for i in response.FireinfoList:
|
for i in response.FireinfoList:
|
||||||
if i.fire == 3: # 发现气瓶倾倒
|
if i.fire == 3: # 发现气瓶倾倒
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
import os
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
myLogger = logging.getLogger('log')
|
myLogger = logging.getLogger('log')
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,8 +11,8 @@ algo_dict = {
|
||||||
"helmet": "apps.ai.client.helmet",
|
"helmet": "apps.ai.client.helmet",
|
||||||
"fire1": "apps.ai.client.fire1",
|
"fire1": "apps.ai.client.fire1",
|
||||||
"fangtang": "apps.ai.client.fangtang",
|
"fangtang": "apps.ai.client.fangtang",
|
||||||
"jingjiedai": "apps.ai.jingjiedai",
|
"jingjiedai": "apps.ai.client.jingjiedai",
|
||||||
"qiping": "apps.ai.qiping"
|
"qiping": "apps.ai.client.qiping"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +24,13 @@ def ai_analyse(codes: list, global_img: str, face_img: str = None):
|
||||||
global_img (str): 全景图片地址
|
global_img (str): 全景图片地址
|
||||||
face_img (str): 人脸图片地址
|
face_img (str): 人脸图片地址
|
||||||
"""
|
"""
|
||||||
|
from apps.ecm.service import save_dahua_pic
|
||||||
results = {} # dict key: 触发的事件标识字符 value: 多个矩形框坐标列表
|
results = {} # dict key: 触发的事件标识字符 value: 多个矩形框坐标列表
|
||||||
|
global_img_path = save_dahua_pic(global_img)
|
||||||
|
global_img = settings.BASE_URL_OUT + global_img_path
|
||||||
|
if face_img:
|
||||||
|
face_img_path = save_dahua_pic(face_img)
|
||||||
|
face_img = settings.BASE_URL_OUT + face_img_path
|
||||||
for i in codes:
|
for i in codes:
|
||||||
if i in algo_dict and i not in results: # 如果算法支持且没有识别过
|
if i in algo_dict and i not in results: # 如果算法支持且没有识别过
|
||||||
module, func = algo_dict[i].rsplit(".", 1)
|
module, func = algo_dict[i].rsplit(".", 1)
|
||||||
|
@ -56,4 +64,7 @@ def ai_analyse(codes: list, global_img: str, face_img: str = None):
|
||||||
results.update({i: {'rectangles': rectangle_dict.get(i, [])}})
|
results.update({i: {'rectangles': rectangle_dict.get(i, [])}})
|
||||||
except Exception:
|
except Exception:
|
||||||
myLogger.error('算法处理错误', exc_info=True)
|
myLogger.error('算法处理错误', exc_info=True)
|
||||||
|
os.remove(settings.BASE_DIR + global_img_path) # 删除临时图片
|
||||||
|
if face_img:
|
||||||
|
os.remove(settings.BASE_DIR + face_img_path)
|
||||||
return results
|
return results
|
||||||
|
|
Loading…
Reference in New Issue