算法测试

This commit is contained in:
caoqianming 2023-02-13 16:09:50 +08:00
parent d638448fa6
commit a7d60d69ae
2 changed files with 13 additions and 10 deletions

View File

@ -53,7 +53,6 @@ def ai_analyse(codes: list, global_img: str, face_img: str = '', is_dahua_pic: b
is_happend, res = getattr(m, 'helmet2')(ip=settings.AI_IP, pic_url=global_img) is_happend, res = getattr(m, 'helmet2')(ip=settings.AI_IP, pic_url=global_img)
else: else:
is_happend, res = f(ip=settings.AI_IP, pic_url=global_img) is_happend, res = f(ip=settings.AI_IP, pic_url=global_img)
myLogger.info(res)
if i in ['fire1', 'jingjiedai', 'qiping']: # 如果是这3类算法就无需再识别都在一个算法里处理了 if i in ['fire1', 'jingjiedai', 'qiping']: # 如果是这3类算法就无需再识别都在一个算法里处理了
has_fire = False # 默认没有灭火器 has_fire = False # 默认没有灭火器
has_jingjiedai = False # 默认没有警戒带 has_jingjiedai = False # 默认没有警戒带
@ -72,7 +71,6 @@ def ai_analyse(codes: list, global_img: str, face_img: str = '', is_dahua_pic: b
results.update({i: rectangle_dict.get(i, [])}) results.update({i: rectangle_dict.get(i, [])})
if is_happend and (i not in results): if is_happend and (i not in results):
results.update({i: rectangle_dict.get(i, [])}) results.update({i: rectangle_dict.get(i, [])})
myLogger.info(results)
except Exception: except Exception:
myLogger.error('算法处理错误', exc_info=True) myLogger.error('算法处理错误', exc_info=True)
if global_img_path: if global_img_path:
@ -91,12 +89,15 @@ def ai_analyse_2(codes: list, global_img: str, face_img: str = '', is_dahua_pic:
face_img (str): 人脸图片url地址 face_img (str): 人脸图片url地址
""" """
results = ai_analyse(codes, global_img, face_img, is_dahua_pic) results = ai_analyse(codes, global_img, face_img, is_dahua_pic)
if results and is_dahua_pic: # 如果触发事件且是大华图片先保存下来 try:
from apps.ecm.service import save_dahua_pic if results and is_dahua_pic: # 如果触发事件且是大华图片先保存下来
global_img_path = save_dahua_pic(global_img) from apps.ecm.service import save_dahua_pic
global_img_local = settings.BASE_DIR + global_img_path global_img_path = save_dahua_pic(global_img)
draw(global_img_local, results) # 绘制矩形框 global_img_local = settings.BASE_DIR + global_img_path
results.update({'global_img': global_img_path}) draw(global_img_local, results) # 绘制矩形框
results.update({'global_img': global_img_path})
except Exception as e:
myLogger.error('算法返回信息处理错误', exc_info=True)
return results return results

View File

@ -250,9 +250,11 @@ class TestViewSet(CustomGenericViewSet):
测试抓图识别 测试抓图识别
""" """
code = request.data['code'] code = request.data['code']
codes = request.data['codes']
opl_id = request.data['opl']
vc = TDevice.objects.get(code=code) vc = TDevice.objects.get(code=code)
snap_and_analyse(vc, ['fire1', 'helmet'], snap_and_analyse(vc, codes,
Opl.objects.get(id='1572195171456651264')) Opl.objects.get(id=opl_id))
return Response() return Response()
@action(methods=['post'], detail=False, serializer_class=Serializer) @action(methods=['post'], detail=False, serializer_class=Serializer)