save_dahua_pic提供自定义路径
This commit is contained in:
parent
874d427df3
commit
a787c02fa6
|
@ -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: # 如果算法支持且没有识别过
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue