This commit is contained in:
曹前明 2022-10-30 21:57:52 +08:00
commit f2aadec871
6 changed files with 34 additions and 22 deletions

View File

@ -30,10 +30,10 @@ def ai_analyse(codes: list, global_img: str, face_img: str = '', is_dahua_pic: b
face_img_path = ''
if is_dahua_pic: # 先保存到本地/主要是现在算法必须得用可访问的远程地址
from apps.ecm.service import save_dahua_pic
global_img_path = save_dahua_pic(global_img)
global_img_path = save_dahua_pic(global_img, '/media/temp/')
global_img = settings.BASE_URL_OUT + global_img_path # 用新地址
if face_img:
face_img_path = save_dahua_pic(face_img)
face_img_path = save_dahua_pic(face_img, '/media/temp/')
face_img = settings.BASE_URL_OUT + face_img_path
for i in codes:
if i in algo_dict and i not in results: # 如果算法支持且没有识别过
@ -42,9 +42,11 @@ def ai_analyse(codes: list, global_img: str, face_img: str = '', is_dahua_pic: b
f = getattr(m, func)
try:
is_happend, res, rectangle_dict = False, None, {}
if i == 'helmet': # 如果是安全帽抠图识别
if face_img:
if i == 'helmet': # 如果是安全帽识别
if face_img: # 如果有小图
is_happend, res = f(ip=settings.AI_IP, pic_url=face_img)
# if is_happend: # 补偿机制: 如果小图识别为未带安全帽,为了保证正确率,再用大图识别一次
# is_happend, res = getattr(m, 'helmet2')(ip=settings.AI_IP, pic_url=global_img)
else:
is_happend, res = getattr(m, 'helmet2')(ip=settings.AI_IP, pic_url=global_img)
else:
@ -55,7 +57,7 @@ def ai_analyse(codes: list, global_img: str, face_img: str = '', is_dahua_pic: b
qiping_qd = False # 气瓶倾倒未发生
rectangle_dict .update({'qiping': []}) # 气瓶倾倒的坐标字典
for x in res.FireinfoList:
if x.fire == 3 and 'qiping' in codes: # 气瓶倾倒
if x.fire == 3: # 气瓶倾倒
qiping_qd = True
rectangle_dict['qiping'].append(
[(x.coord.uleft.x, x.coord.uleft.y), (x.coord.lright.x, x.coord.lright.y)]) # 加入矩形框
@ -89,7 +91,7 @@ def ai_analyse_2(codes: list, global_img: str, face_img: str = '', is_dahua_pic:
from apps.ecm.service import save_dahua_pic
global_img_path = save_dahua_pic(global_img)
global_img_local = settings.BASE_DIR + global_img_path
draw(global_img_local, results)
draw(global_img_local, results) # 绘制矩形框
results.update({'global_img': global_img_path})
return results

View File

@ -45,13 +45,13 @@ def get_area_info_from_cache(target: str, cache: list):
return None
def save_dahua_pic(pic_url: str):
def save_dahua_pic(pic_url: str, save_path: str = '/media/'):
"""保存大华报警图片到本地(全路径)
返回本地路径
"""
file_name = pic_url.split('/')[-1].split('?')[0]
res = requests.get(url=pic_url, verify=False)
path = '/media/' + timezone.now().strftime('%Y/%m/%d/')
path = save_path + timezone.now().strftime('%Y/%m/%d/')
full_path = settings.BASE_DIR + path
if not os.path.exists(full_path):
os.makedirs(full_path)

View File

@ -1,19 +1,36 @@
from __future__ import absolute_import, unicode_literals
import os
from threading import Thread
from celery import shared_task
import requests
from apps.am.models import Area
from apps.ecm.models import EventCate, Eventdo, Event
from apps.ecm.service import notify_event, snap_and_analyse
from apps.hrm.models import Employee
from apps.opm.models import Opl
from apps.third.dahua import dhClient
from apps.third.xunxi import xxClient
from apps.third.models import TDevice
from apps.third.tapis import xxapis
from django.utils import timezone
import time
from django.core.cache import cache
from django.conf import settings
def store_img(code: str, duration: int):
while True:
global_img = dhClient.snap(code)
file_name = global_img.split('/')[-1].split('?')[0]
res = requests.get(url=global_img, verify=False)
path = '/media/temp/store_img/'
full_path = settings.BASE_DIR + path
if not os.path.exists(full_path):
os.makedirs(full_path)
with open(full_path + file_name, 'wb') as f:
f.write(res.content)
time.sleep(duration)
def update_count_people(i: Area):

View File

@ -81,7 +81,7 @@ class BltViewSet(CustomGenericViewSet):
area = Area.objects.get(id=data['area'])
railId = area.third_info['xx_rail']['id']
except Exception:
raise ParseError('区域信息不正确')
raise ParseError('围栏未绘制')
json = {
"railId": railId,
"type": ""

View File

@ -50,7 +50,7 @@ class VisitorCreateSerializer(CustomModelSerializer):
phone = serializers.CharField(label="手机号", validators=[check_phone_e])
photo = serializers.CharField(label='照片地址', required=True)
id_number = serializers.CharField(
label="身份证号", validators=[check_id_number_e])
label="身份证号", validators=[check_id_number_e], required=True)
class Meta:
model = Visitor

View File

@ -29,7 +29,8 @@ class VisitViewSet(CustomModelViewSet):
serializer_class = VisitSerializer
retrieve_serializer_class = VisitDetailSerializer
filterset_fields = ['state', 'create_by', 'purpose']
select_related_fields = ['ticket', 'receptionist', 'ticket__workflow', 'ticket__state']
select_related_fields = ['ticket', 'receptionist',
'ticket__workflow', 'ticket__state']
def get_queryset(self):
user = self.request.user
@ -58,17 +59,9 @@ class VisitViewSet(CustomModelViewSet):
raise ParseError('该项目人员在厂不可删除')
return super().destroy(request, *args, **kwargs)
# @action(methods=['post'], detail=True, permission_classes=[],
# serializer_class=Serializer)
# @transaction.atomic
# def submit(self, request, *args, **kwargs):
# """司机直接提交不走工单
# 司机直接提交不走工单
# """
# obj = self.get_object()
# visit_driver_end(obj)
# return Response()
@action(methods=['get'], detail=False, perms_map={'get': '*'}, serializer_class=Serializer)
def export_excel(self, request, pk=None):
return Response()
class VisitorViewSet(CustomModelViewSet):