Compare commits
5 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
610670fd46 | |
|
|
d61146f244 | |
|
|
8e49836d6e | |
|
|
030d30e4e8 | |
|
|
855ba1bb40 |
10
README.md
10
README.md
|
|
@ -1,8 +1,2 @@
|
||||||
1.2025.01.21把之前的tuoheng alg仓库代码重新开个仓库 (1)在config/service/dsp_test_service.yml里面添加参数,控制存储用的oss还是minio storage_source: 1 2.2025.02.06 (1)修改代码,把mqtt读取加入到系统中。config/service/dsp_test_service.yml,中添加mqtt_flag,决定是否启用。 (2)修改了minio情况下的,文件名命名方式。 3.2025.02.12 (1)增加了对alg算法开发的代码。可以通过配置文件config/service/dsp_test_service.yml中algSwitch: true,决定是否启用。
|
1.dsj
|
||||||
|
2.0811
|
||||||
4、2025.07.10 周树亮 - 增加人群计数,自研车牌模型,裸土覆盖3个场景
|
|
||||||
|
|
||||||
5、江朝庆 -- 0715
|
|
||||||
1)代码整理,删除冗余代码。
|
|
||||||
2)增加requirements.txt,方便部署
|
|
||||||
3) logs
|
|
||||||
|
|
@ -6,21 +6,25 @@ from traceback import format_exc
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
import cv2
|
import cv2
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import base64
|
||||||
from entity.FeedBack import message_feedback
|
from entity.FeedBack import message_feedback
|
||||||
from enums.ExceptionEnum import ExceptionType
|
from enums.ExceptionEnum import ExceptionType
|
||||||
from enums.ModelTypeEnum import ModelType
|
|
||||||
from exception.CustomerException import ServiceException
|
from exception.CustomerException import ServiceException
|
||||||
from util.AliyunSdk import AliyunOssSdk
|
from util.AliyunSdk import AliyunOssSdk
|
||||||
from util.MinioSdk import MinioSdk
|
from util.MinioSdk import MinioSdk
|
||||||
from util import TimeUtils
|
from util import TimeUtils
|
||||||
from enums.AnalysisStatusEnum import AnalysisStatus
|
from enums.AnalysisStatusEnum import AnalysisStatus
|
||||||
from util.PlotsUtils import draw_painting_joint, draw_name_ocr, draw_name_crowd
|
from util.PlotsUtils import draw_painting_joint
|
||||||
from util.QueUtil import put_queue, get_no_block_queue, clear_queue
|
from util.QueUtil import put_queue, get_no_block_queue, clear_queue
|
||||||
import io
|
import io
|
||||||
from util.LocationUtils import locate_byMqtt
|
from util.LocationUtils import locate_byMqtt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FileUpload(Thread):
|
class FileUpload(Thread):
|
||||||
__slots__ = ('_fb_queue', '_context', '_image_queue', '_analyse_type', '_msg','_mqtt_list')
|
__slots__ = ('_fb_queue', '_context', '_image_queue', '_analyse_type', '_msg', '_mqtt_list')
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
@ -33,6 +37,16 @@ class FileUpload(Thread):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.server_ip = self._context['llm']['server_ip']
|
||||||
|
self.server_port = self._context['llm']['server_port']
|
||||||
|
self.is_use_llm = self._context['llm']['is_use_llm']
|
||||||
|
self.cnt = self._context['llm']['cnt']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#0521:
|
#0521:
|
||||||
default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true"
|
default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true"
|
||||||
if default_enabled:
|
if default_enabled:
|
||||||
|
|
@ -44,15 +58,74 @@ class FileUpload(Thread):
|
||||||
# 这里放非默认逻辑的代码
|
# 这里放非默认逻辑的代码
|
||||||
self._algSwitch = False
|
self._algSwitch = False
|
||||||
|
|
||||||
print("---line46 :FileUploadThread.py---",self._algSwitch)
|
# 如果任务是在线、离线处理,则用此类
|
||||||
|
|
||||||
|
|
||||||
#如果任务是在线、离线处理,则用此类
|
|
||||||
class ImageFileUpload(FileUpload):
|
class ImageFileUpload(FileUpload):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
|
def extract_answers(self, text): # 提取大模型中的分点文本内容
|
||||||
|
lines = [line.strip() for line in text.split('.') if line.strip()]
|
||||||
|
answers = []
|
||||||
|
for i, line in enumerate(lines):
|
||||||
|
if i > 0:
|
||||||
|
if i < len(lines) - 1:
|
||||||
|
answers.append(line[:-1])
|
||||||
|
else:
|
||||||
|
answers.append(line)
|
||||||
|
return answers
|
||||||
|
|
||||||
|
def get_llm_res(self, image, prompt,SERVER_IP,API_PORT):
|
||||||
|
|
||||||
|
# SERVER_IP = "192.168.10.11"
|
||||||
|
# API_URL = f"http://{SERVER_IP}:8000/generate"
|
||||||
|
|
||||||
|
SERVER_IP = SERVER_IP
|
||||||
|
|
||||||
|
API_URL = f"http://{SERVER_IP}:{API_PORT}/generate"
|
||||||
|
|
||||||
|
# _, buffer = cv2.imencode('.jpg', image)
|
||||||
|
# is_success, buffer = cv2.imencode('.png', image)
|
||||||
|
is_success, buffer = cv2.imencode('.webp', image, [cv2.IMWRITE_WEBP_QUALITY, 100])
|
||||||
|
image_base64 = base64.b64encode(buffer).decode('utf-8')
|
||||||
|
|
||||||
|
conversation = {
|
||||||
|
"prompt": prompt,
|
||||||
|
"image_base64": image_base64,
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger.info(f"正在向 {API_URL} 发送请求...")
|
||||||
|
response = requests.post(API_URL, json=conversation, timeout=60) # 设置超时
|
||||||
|
|
||||||
|
response.raise_for_status() # 如果状态码不是2xx,会抛出异常
|
||||||
|
|
||||||
|
resp = response.json()
|
||||||
|
result = resp.get("response")
|
||||||
|
|
||||||
|
logger.info("\n--- 请求成功 ---")
|
||||||
|
logger.info(f"原始Prompt: {prompt}")
|
||||||
|
logger.info(f"模型生成结果: {result}")
|
||||||
|
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
logger.info(f"\n--- 请求失败 ---")
|
||||||
|
logger.info(f"发生错误: {e}")
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
logger.info("\n--- 解析失败 ---")
|
||||||
|
logger.info(f"无法解析服务器返回的响应: {response.text}")
|
||||||
|
|
||||||
|
new_result = self.extract_answers(result)
|
||||||
|
print("###line116",new_result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
new_result = new_result[1] # 获取第二点内容
|
||||||
|
# flag = "不" in result or ("没" in result and "没错" not in result) or "否" in result or "未" in result or "无" in result
|
||||||
|
flag = "不存在" in new_result or ("没" in new_result and "没错" not in new_result) or (
|
||||||
|
"否" in new_result and "是否" not in new_result) or "未" in new_result or "无法" in new_result
|
||||||
|
return not flag, new_result
|
||||||
|
|
||||||
#@staticmethod
|
#@staticmethod
|
||||||
def handle_image(self,frame_msg, frame_step):
|
def handle_image(self, frame_msg, frame_step):
|
||||||
# (high_score_image["code"], all_frames, draw_config["font_config"])
|
# (high_score_image["code"], all_frames, draw_config["font_config"])
|
||||||
# high_score_image["code"][code][cls] = (frame, frame_index_list[i], cls_list)
|
# high_score_image["code"][code][cls] = (frame, frame_index_list[i], cls_list)
|
||||||
det_xywh, frame, current_frame, all_frames, font_config = frame_msg
|
det_xywh, frame, current_frame, all_frames, font_config = frame_msg
|
||||||
|
|
@ -67,7 +140,6 @@ class ImageFileUpload(FileUpload):
|
||||||
'''
|
'''
|
||||||
print('*'*100,' mqtt_list:',len(self._mqtt_list))
|
print('*'*100,' mqtt_list:',len(self._mqtt_list))
|
||||||
|
|
||||||
|
|
||||||
model_info = []
|
model_info = []
|
||||||
# 更加模型编码解析数据
|
# 更加模型编码解析数据
|
||||||
for code, det_list in det_xywh.items():
|
for code, det_list in det_xywh.items():
|
||||||
|
|
@ -76,27 +148,15 @@ class ImageFileUpload(FileUpload):
|
||||||
if len(target_list) > 0:
|
if len(target_list) > 0:
|
||||||
aFrame = frame.copy()
|
aFrame = frame.copy()
|
||||||
for target in target_list:
|
for target in target_list:
|
||||||
# 自研车牌模型判断
|
draw_painting_joint(target[1], aFrame, target[3], target[2], target[4], font_config, target[5])
|
||||||
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
igH,igW = aFrame.shape[0:2]
|
||||||
box = [target[1][0][0], target[1][0][1], target[1][3][0], target[1][3][1]]
|
if len(self._mqtt_list)>=1:
|
||||||
draw_name_ocr(box, aFrame, target[4], target[0])
|
#camParas = self._mqtt_list[0]['data']
|
||||||
cls = 0
|
|
||||||
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
|
||||||
draw_name_crowd(target[3], aFrame, target[4], cls)
|
|
||||||
cls = 0
|
|
||||||
else:
|
|
||||||
draw_painting_joint(target[1], aFrame, target[3], target[2], target[4], font_config,
|
|
||||||
target[5])
|
|
||||||
|
|
||||||
igH, igW = aFrame.shape[0:2]
|
|
||||||
if len(self._mqtt_list) >= 1:
|
|
||||||
# camParas = self._mqtt_list[0]['data']
|
|
||||||
camParas = self._mqtt_list[0]
|
camParas = self._mqtt_list[0]
|
||||||
gps = locate_byMqtt(target[1], igW, igH, camParas, outFormat='wgs84')
|
gps = locate_byMqtt(target[1],igW,igH,camParas,outFormat='wgs84')
|
||||||
else:
|
else:
|
||||||
gps = [None, None]
|
gps=[None,None]
|
||||||
model_info.append(
|
model_info.append({"modelCode": str(code), "detectTargetCode": str(cls), "aFrame": aFrame,'gps':gps})
|
||||||
{"modelCode": str(code), "detectTargetCode": str(cls), "aFrame": aFrame, 'gps': gps})
|
|
||||||
if len(model_info) > 0:
|
if len(model_info) > 0:
|
||||||
image_result = {
|
image_result = {
|
||||||
"or_frame": frame,
|
"or_frame": frame,
|
||||||
|
|
@ -153,30 +213,89 @@ class ImageFileUpload(FileUpload):
|
||||||
image_result["last_frame"],
|
image_result["last_frame"],
|
||||||
analyse_type,
|
analyse_type,
|
||||||
"OR", "0", "0", request_id)
|
"OR", "0", "0", request_id)
|
||||||
if self._storage_source==1:
|
if self._storage_source==1:
|
||||||
or_future = t.submit(minioSdk.put_object, or_image,or_image_name)
|
or_future = t.submit(minioSdk.put_object, or_image, or_image_name)
|
||||||
else:
|
else:
|
||||||
or_future = t.submit(aliyunOssSdk.put_object, or_image_name, or_image.tobytes())
|
or_future = t.submit(aliyunOssSdk.put_object, or_image_name, or_image.tobytes())
|
||||||
task.append(or_future)
|
task.append(or_future)
|
||||||
model_info_list = image_result["model_info"]
|
model_info_list = image_result["model_info"]
|
||||||
|
llm_flag_list = []
|
||||||
msg_list = []
|
msg_list = []
|
||||||
for model_info in model_info_list:
|
|
||||||
ai_image = cv2.imencode(".jpg", model_info["aFrame"])[1]
|
|
||||||
ai_image_name = build_image_name(image_result["current_frame"],
|
|
||||||
image_result["last_frame"],
|
|
||||||
analyse_type,
|
|
||||||
"AI",
|
|
||||||
model_info["modelCode"],
|
|
||||||
model_info["detectTargetCode"],
|
|
||||||
request_id)
|
|
||||||
if self._storage_source==1:
|
|
||||||
ai_future = t.submit(minioSdk.put_object, ai_image,
|
|
||||||
ai_image_name)
|
|
||||||
else:
|
|
||||||
ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name,
|
|
||||||
ai_image.tobytes())
|
|
||||||
|
|
||||||
task.append(ai_future)
|
|
||||||
|
for model_info in model_info_list:
|
||||||
|
|
||||||
|
fire_flag = model_info.get("modelCode")
|
||||||
|
print("###line229",fire_flag)
|
||||||
|
|
||||||
|
if fire_flag == "008":
|
||||||
|
|
||||||
|
aFrame = model_info["aFrame"]
|
||||||
|
# aFrame_rgb = cv2.cvtColor(aFrame, cv2.COLOR_BGR2RGB)
|
||||||
|
|
||||||
|
tar_cls = model_info["detectTargetCode"]
|
||||||
|
logger.info("目标类别:{}", tar_cls)
|
||||||
|
|
||||||
|
# 0715 : 这块也不对,因为需要具体到目标才可以,否则只看0 1 ,是无法做到判断正确的火情处理,还有大量其他的部分
|
||||||
|
|
||||||
|
# is_use_llm = True
|
||||||
|
if tar_cls == '0':
|
||||||
|
# tar = "明火"
|
||||||
|
tar = "2. 判断图中是否有明火。3. 如果有,识别火势的大小,比如:[无情况/小/中/大]"
|
||||||
|
elif tar_cls == '1':
|
||||||
|
# tar = "某种物质燃烧产生的烟雾"
|
||||||
|
tar = "2. 判断图中是否有烟雾。3. 如果有,识别烟雾的颜色,比如:[无烟雾/白/灰白/灰黑]"
|
||||||
|
else:
|
||||||
|
self.is_use_llm = False
|
||||||
|
|
||||||
|
llm_flag = True
|
||||||
|
if self.is_use_llm:
|
||||||
|
# prompt = f"我看到图中有{tar},请你判断是否正确。简要回答。"
|
||||||
|
prompt = f"分点进行输出:1. 简短描述图像中的场景。{tar}"
|
||||||
|
logger.info("检测到目标,大模型提示词:{}", prompt)
|
||||||
|
|
||||||
|
|
||||||
|
# llm_flag, llm_res = self.get_llm_res(aFrame, prompt)
|
||||||
|
|
||||||
|
|
||||||
|
llm_flag, llm_res = self.get_llm_res(aFrame, prompt,self.server_ip,self.server_port)
|
||||||
|
|
||||||
|
llm_flag_list.append(llm_flag)
|
||||||
|
logger.info("检测到目标,大模型识别图中是否存在目标:{}, 大模型输出:{}", llm_flag, llm_res)
|
||||||
|
|
||||||
|
if llm_flag:
|
||||||
|
logger.info("经大模型筛查,小模型识别正确!!!")
|
||||||
|
# cv2.imwrite(f"/home/thsw2/wei/image_res/{self.cnt}_{tar_cls}_1.jpg", aFrame, [cv2.IMWRITE_JPEG_QUALITY, 80])
|
||||||
|
# self.cnt = self.cnt + 1
|
||||||
|
else:
|
||||||
|
logger.info("经大模型筛查,小模型识别错误!!!")
|
||||||
|
# cv2.imwrite(f"/home/thsw2/wei/image_res/{self.cnt}_{tar_cls}_0.jpg", aFrame, [cv2.IMWRITE_JPEG_QUALITY, 80])
|
||||||
|
# self.cnt = self.cnt + 1
|
||||||
|
else:
|
||||||
|
llm_flag_list.append(llm_flag)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ai_image = cv2.imencode(".jpg", aFrame)[1]
|
||||||
|
ai_image_name = build_image_name(image_result["current_frame"],
|
||||||
|
image_result["last_frame"],
|
||||||
|
analyse_type,
|
||||||
|
"AI",
|
||||||
|
model_info["modelCode"],
|
||||||
|
model_info["detectTargetCode"],
|
||||||
|
request_id)
|
||||||
|
if llm_flag: # 根据大模型结果判定是否上传
|
||||||
|
if self._storage_source==1:
|
||||||
|
ai_future = t.submit(minioSdk.put_object, ai_image,
|
||||||
|
ai_image_name)
|
||||||
|
else:
|
||||||
|
ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name,
|
||||||
|
ai_image.tobytes())
|
||||||
|
|
||||||
|
task.append(ai_future)
|
||||||
|
|
||||||
|
# print("###line288",len(task))
|
||||||
|
|
||||||
#msg_list.append(message_feedback(request_id,
|
#msg_list.append(message_feedback(request_id,
|
||||||
# AnalysisStatus.RUNNING.value,
|
# AnalysisStatus.RUNNING.value,
|
||||||
# analyse_type, "", "", "",
|
# analyse_type, "", "", "",
|
||||||
|
|
@ -184,21 +303,25 @@ class ImageFileUpload(FileUpload):
|
||||||
# ai_image_name,
|
# ai_image_name,
|
||||||
# model_info['modelCode'],
|
# model_info['modelCode'],
|
||||||
# model_info['detectTargetCode']))
|
# model_info['detectTargetCode']))
|
||||||
remote_image_list=[]
|
|
||||||
for tk in task:
|
|
||||||
remote_image_list.append( tk.result())
|
|
||||||
|
|
||||||
for ii,model_info in enumerate(model_info_list):
|
remote_image_list = []
|
||||||
msg_list.append( message_feedback(request_id,
|
for tk in task:
|
||||||
AnalysisStatus.RUNNING.value,
|
remote_image_list.append( tk.result() )
|
||||||
analyse_type, "", "", "",
|
|
||||||
remote_image_list[0],
|
for ii, model_info in enumerate(model_info_list):
|
||||||
remote_image_list[ii+1],
|
|
||||||
model_info['modelCode'],
|
if llm_flag_list[ii]:
|
||||||
model_info['detectTargetCode'],
|
msg_list.append( message_feedback(request_id,
|
||||||
longitude=model_info['gps'][0],
|
AnalysisStatus.RUNNING.value,
|
||||||
latitude=model_info['gps'][1],
|
analyse_type, "", "", "",
|
||||||
) )
|
remote_image_list[0],
|
||||||
|
remote_image_list[ii+1],
|
||||||
|
model_info['modelCode'],
|
||||||
|
model_info['detectTargetCode'],
|
||||||
|
longitude=model_info['gps'][0],
|
||||||
|
latitude=model_info['gps'][1],
|
||||||
|
) )
|
||||||
|
|
||||||
|
|
||||||
if (not self._algSwitch) or ( self._algStatus and self._algSwitch):
|
if (not self._algSwitch) or ( self._algStatus and self._algSwitch):
|
||||||
for msg in msg_list:
|
for msg in msg_list:
|
||||||
|
|
@ -254,20 +377,12 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
if target_list is not None and len(target_list) > 0:
|
if target_list is not None and len(target_list) > 0:
|
||||||
aiFrame = copy_frame.copy()
|
aiFrame = copy_frame.copy()
|
||||||
for target in target_list:
|
for target in target_list:
|
||||||
# 自研车牌模型判断
|
draw_painting_joint(target[1], aiFrame, target[3], target[2], target[4], font_config)
|
||||||
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
model_info.append({
|
||||||
draw_name_ocr(target[1], aiFrame, font_config[cls], target[0])
|
"modelCode": str(code),
|
||||||
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
"detectTargetCode": str(cls),
|
||||||
draw_name_crowd(target[1],aiFrame,font_config[cls],target[0])
|
"frame": aiFrame
|
||||||
else:
|
})
|
||||||
draw_painting_joint(target[1], aiFrame, target[3], target[2], target[4], font_config)
|
|
||||||
|
|
||||||
model_info.append({
|
|
||||||
"modelCode": str(code),
|
|
||||||
"detectTargetCode": str(cls),
|
|
||||||
"frame": aiFrame
|
|
||||||
})
|
|
||||||
|
|
||||||
if len(model_info) > 0:
|
if len(model_info) > 0:
|
||||||
image_result = {
|
image_result = {
|
||||||
"or_frame": copy_frame,
|
"or_frame": copy_frame,
|
||||||
|
|
@ -313,7 +428,7 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
ai_image_name = build_image_name(0, 0, analyse_type, "AI", result.get("modelCode"),
|
ai_image_name = build_image_name(0, 0, analyse_type, "AI", result.get("modelCode"),
|
||||||
result.get("type"), request_id)
|
result.get("type"), request_id)
|
||||||
|
|
||||||
if self._storage_source==1:
|
if self._storage_source==1:
|
||||||
ai_future = t.submit(minioSdk.put_object, copy_frame,ai_image_name)
|
ai_future = t.submit(minioSdk.put_object, copy_frame,ai_image_name)
|
||||||
else:
|
else:
|
||||||
ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name, copy_frame)
|
ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name, copy_frame)
|
||||||
|
|
@ -340,7 +455,7 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
analyse_type,
|
analyse_type,
|
||||||
"OR", "0", "O", request_id)
|
"OR", "0", "O", request_id)
|
||||||
|
|
||||||
if self._storage_source==1:
|
if self._storage_source==1:
|
||||||
or_future = t.submit(minioSdk.put_object, or_image,image_url_0)
|
or_future = t.submit(minioSdk.put_object, or_image,image_url_0)
|
||||||
else:
|
else:
|
||||||
or_future = t.submit(aliyunOssSdk.put_object, image_url_0,
|
or_future = t.submit(aliyunOssSdk.put_object, image_url_0,
|
||||||
|
|
@ -357,7 +472,7 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
model_info.get("modelCode"),
|
model_info.get("modelCode"),
|
||||||
model_info.get("detectTargetCode"),
|
model_info.get("detectTargetCode"),
|
||||||
request_id)
|
request_id)
|
||||||
if self._storage_source==1:
|
if self._storage_source==1:
|
||||||
ai_future = t.submit(minioSdk.put_object, ai_image, ai_image_name)
|
ai_future = t.submit(minioSdk.put_object, ai_image, ai_image_name)
|
||||||
else:
|
else:
|
||||||
ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name,
|
ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name,
|
||||||
|
|
@ -376,7 +491,8 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
for thread_result in task:
|
for thread_result in task:
|
||||||
remote_url_list.append(thread_result.result())
|
remote_url_list.append(thread_result.result())
|
||||||
|
|
||||||
# 以下代码是为了获取图像上传后,返回的全路径地址
|
|
||||||
|
#以下代码是为了获取图像上传后,返回的全路径地址
|
||||||
if det_xywh is None:
|
if det_xywh is None:
|
||||||
msg_list.append(message_feedback(request_id,
|
msg_list.append(message_feedback(request_id,
|
||||||
AnalysisStatus.RUNNING.value,
|
AnalysisStatus.RUNNING.value,
|
||||||
|
|
@ -409,6 +525,10 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
model_info_list[ii].get('detectTargetCode'),
|
model_info_list[ii].get('detectTargetCode'),
|
||||||
analyse_results=result))
|
analyse_results=result))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for msg in msg_list:
|
for msg in msg_list:
|
||||||
put_queue(fb_queue, msg, timeout=2, is_ex=False)
|
put_queue(fb_queue, msg, timeout=2, is_ex=False)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ from util.Cv2Utils import video_conjuncing, write_or_video, write_ai_video, push
|
||||||
from util.ImageUtils import url2Array, add_water_pic
|
from util.ImageUtils import url2Array, add_water_pic
|
||||||
from util.LogUtils import init_log
|
from util.LogUtils import init_log
|
||||||
|
|
||||||
from util.PlotsUtils import draw_painting_joint, filterBox, xywh2xyxy2, xy2xyxy, draw_name_joint, plot_one_box_auto, draw_name_ocr,draw_name_crowd
|
from util.PlotsUtils import draw_painting_joint, filterBox, xywh2xyxy2, draw_name_joint
|
||||||
|
|
||||||
from util.QueUtil import get_no_block_queue, put_queue, clear_queue
|
from util.QueUtil import get_no_block_queue, put_queue, clear_queue
|
||||||
|
|
||||||
|
|
@ -50,8 +50,15 @@ class PushStreamProcess(Process):
|
||||||
# 这里放非默认逻辑的代码
|
# 这里放非默认逻辑的代码
|
||||||
self._algSwitch = False
|
self._algSwitch = False
|
||||||
|
|
||||||
|
|
||||||
print("---line53 :PushVideoStreamProcess.py---",self._algSwitch)
|
print("---line53 :PushVideoStreamProcess.py---",self._algSwitch)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_logo_url(self):
|
def build_logo_url(self):
|
||||||
logo = None
|
logo = None
|
||||||
if self._context["video"]["video_add_water"]:
|
if self._context["video"]["video_add_water"]:
|
||||||
|
|
@ -148,39 +155,17 @@ class OnPushStreamProcess(PushStreamProcess):
|
||||||
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
|
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
|
||||||
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
|
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
|
||||||
for qs in det_result:
|
for qs in det_result:
|
||||||
# 自研车牌模型处理
|
try: # 应对NaN情况
|
||||||
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
box, score, cls = xywh2xyxy2(qs)
|
||||||
cls = 0
|
except:
|
||||||
ocrlabel, xybox = qs
|
continue
|
||||||
box = xy2xyxy(xybox)
|
if cls not in allowedList or score < frame_score:
|
||||||
score = None
|
continue
|
||||||
color = rainbows[cls]
|
label_array, color = label_arrays[cls], rainbows[cls]
|
||||||
label_array = None
|
if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
|
||||||
rr = t.submit(draw_name_ocr, xybox, copy_frame, color, ocrlabel)
|
rr = t.submit(draw_name_joint, box, copy_frame, draw_config[code]["label_dict"], score, color, font_config, qs[6])
|
||||||
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
|
||||||
cls = 0
|
|
||||||
crowdlabel, points = qs
|
|
||||||
box = [(0, 0), (0, 0), (0, 0), (0, 0)]
|
|
||||||
score = None
|
|
||||||
color = rainbows[cls]
|
|
||||||
label_array = None
|
|
||||||
rr = t.submit(draw_name_crowd, points, copy_frame, color, crowdlabel)
|
|
||||||
else:
|
else:
|
||||||
try: # 应对NaN情况
|
rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config)
|
||||||
box, score, cls = xywh2xyxy2(qs)
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
if cls not in allowedList or score < frame_score:
|
|
||||||
continue
|
|
||||||
label_array, color = label_arrays[cls], rainbows[cls]
|
|
||||||
if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
|
|
||||||
rr = t.submit(draw_name_joint, box, copy_frame,
|
|
||||||
draw_config[code]["label_dict"], score, color,
|
|
||||||
font_config, qs[6])
|
|
||||||
else:
|
|
||||||
rr = t.submit(draw_painting_joint, box, copy_frame, label_array,
|
|
||||||
score, color, font_config)
|
|
||||||
|
|
||||||
thread_p.append(rr)
|
thread_p.append(rr)
|
||||||
if det_xywh.get(code) is None:
|
if det_xywh.get(code) is None:
|
||||||
det_xywh[code] = {}
|
det_xywh[code] = {}
|
||||||
|
|
@ -208,9 +193,13 @@ class OnPushStreamProcess(PushStreamProcess):
|
||||||
r.result()
|
r.result()
|
||||||
#print('----line173:',self._algSwitch,self._algStatus)
|
#print('----line173:',self._algSwitch,self._algStatus)
|
||||||
if self._algSwitch and (not self._algStatus):
|
if self._algSwitch and (not self._algStatus):
|
||||||
frame_merge = video_conjuncing(frame, frame.copy())
|
# frame_merge = video_conjuncing(frame, frame.copy())
|
||||||
|
|
||||||
|
frame_merge = frame.copy()
|
||||||
else:
|
else:
|
||||||
frame_merge = video_conjuncing(frame, copy_frame)
|
# frame_merge = video_conjuncing(frame, copy_frame)
|
||||||
|
|
||||||
|
frame_merge = copy_frame
|
||||||
# 写原视频到本地
|
# 写原视频到本地
|
||||||
write_or_video_result = t.submit(write_or_video, frame, orFilePath, or_video_file,
|
write_or_video_result = t.submit(write_or_video, frame, orFilePath, or_video_file,
|
||||||
or_write_status, request_id)
|
or_write_status, request_id)
|
||||||
|
|
@ -222,7 +211,7 @@ class OnPushStreamProcess(PushStreamProcess):
|
||||||
# 如果有问题, 走下面的逻辑
|
# 如果有问题, 走下面的逻辑
|
||||||
if qs_np is not None:
|
if qs_np is not None:
|
||||||
if len(qs_np.shape) == 1:
|
if len(qs_np.shape) == 1:
|
||||||
qs_np = qs_np[np.newaxis,...]
|
qs_np = qs_np[np.newaxis,...]
|
||||||
qs_np_id = qs_np.copy()
|
qs_np_id = qs_np.copy()
|
||||||
b = np.ones(qs_np_id.shape[0])
|
b = np.ones(qs_np_id.shape[0])
|
||||||
qs_np_id = np.column_stack((qs_np_id,b))
|
qs_np_id = np.column_stack((qs_np_id,b))
|
||||||
|
|
@ -248,7 +237,7 @@ class OnPushStreamProcess(PushStreamProcess):
|
||||||
if q[11] >= 1:
|
if q[11] >= 1:
|
||||||
cls = int(q[9])
|
cls = int(q[9])
|
||||||
if not (cls in new_lab):
|
if not (cls in new_lab):
|
||||||
continue # 为了防止其他类别被带出
|
continue # 为了防止其他类别被带出
|
||||||
code = str(int(q[10])).zfill(3)
|
code = str(int(q[10])).zfill(3)
|
||||||
if det_xywh2.get(code) is None:
|
if det_xywh2.get(code) is None:
|
||||||
det_xywh2[code] = {}
|
det_xywh2[code] = {}
|
||||||
|
|
@ -261,11 +250,6 @@ class OnPushStreamProcess(PushStreamProcess):
|
||||||
is_new = False
|
is_new = False
|
||||||
if q[11] == 1:
|
if q[11] == 1:
|
||||||
is_new = True
|
is_new = True
|
||||||
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
|
||||||
cls = ocrlabel
|
|
||||||
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
|
||||||
cls = crowdlabel
|
|
||||||
label_array = points
|
|
||||||
if cd is None:
|
if cd is None:
|
||||||
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
|
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
|
||||||
else:
|
else:
|
||||||
|
|
@ -390,36 +374,15 @@ class OffPushStreamProcess(PushStreamProcess):
|
||||||
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
|
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
|
||||||
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
|
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
|
||||||
for qs in det_result:
|
for qs in det_result:
|
||||||
# 自研车牌模型处理
|
box, score, cls = xywh2xyxy2(qs)
|
||||||
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
|
||||||
cls = 0
|
|
||||||
ocrlabel, xybox = qs
|
|
||||||
box = xy2xyxy(xybox)
|
|
||||||
score = None
|
|
||||||
color = rainbows[cls]
|
|
||||||
label_array = None
|
|
||||||
label_arrays = [None]
|
|
||||||
rr = t.submit(draw_name_ocr,xybox,copy_frame,color,ocrlabel)
|
|
||||||
|
|
||||||
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
|
||||||
cls = 0
|
|
||||||
crowdlabel, points = qs
|
|
||||||
box = [(0,0),(0,0),(0,0),(0,0)]
|
|
||||||
score = None
|
|
||||||
color = rainbows[cls]
|
|
||||||
label_array = None
|
|
||||||
rr = t.submit(draw_name_crowd, points, copy_frame, color, crowdlabel)
|
|
||||||
|
|
||||||
|
if cls not in allowedList or score < frame_score:
|
||||||
|
continue
|
||||||
|
label_array, color = label_arrays[cls], rainbows[cls]
|
||||||
|
if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
|
||||||
|
rr = t.submit(draw_name_joint, box, copy_frame, draw_config[code]["label_dict"], score, color, font_config, qs[6])
|
||||||
else:
|
else:
|
||||||
box, score, cls = xywh2xyxy2(qs)
|
rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config)
|
||||||
if cls not in allowedList or score < frame_score:
|
|
||||||
continue
|
|
||||||
label_array, color = label_arrays[cls], rainbows[cls]
|
|
||||||
if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
|
|
||||||
rr = t.submit(draw_name_joint, box, copy_frame, draw_config[code]["label_dict"], score, color, font_config, qs[6])
|
|
||||||
else:
|
|
||||||
rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config)
|
|
||||||
|
|
||||||
thread_p.append(rr)
|
thread_p.append(rr)
|
||||||
|
|
||||||
if det_xywh.get(code) is None:
|
if det_xywh.get(code) is None:
|
||||||
|
|
@ -447,9 +410,11 @@ class OffPushStreamProcess(PushStreamProcess):
|
||||||
for r in thread_p:
|
for r in thread_p:
|
||||||
r.result()
|
r.result()
|
||||||
if self._algSwitch and (not self._algStatus):
|
if self._algSwitch and (not self._algStatus):
|
||||||
frame_merge = video_conjuncing(frame, frame.copy())
|
# frame_merge = video_conjuncing(frame, frame.copy())
|
||||||
|
frame_merge = frame.copy()
|
||||||
else:
|
else:
|
||||||
frame_merge = video_conjuncing(frame, copy_frame)
|
# frame_merge = video_conjuncing(frame, copy_frame)
|
||||||
|
frame_merge = copy_frame
|
||||||
# 写识别视频到本地
|
# 写识别视频到本地
|
||||||
write_ai_video_result = t.submit(write_ai_video, frame_merge, aiFilePath,
|
write_ai_video_result = t.submit(write_ai_video, frame_merge, aiFilePath,
|
||||||
ai_video_file,
|
ai_video_file,
|
||||||
|
|
@ -457,9 +422,10 @@ class OffPushStreamProcess(PushStreamProcess):
|
||||||
push_stream_result = t.submit(push_video_stream, frame_merge, push_p, push_url,
|
push_stream_result = t.submit(push_video_stream, frame_merge, push_p, push_url,
|
||||||
p_push_status, request_id)
|
p_push_status, request_id)
|
||||||
|
|
||||||
|
|
||||||
if qs_np is not None:
|
if qs_np is not None:
|
||||||
if len(qs_np.shape) == 1:
|
if len(qs_np.shape) == 1:
|
||||||
qs_np = qs_np[np.newaxis,...]
|
qs_np = qs_np[np.newaxis,...]
|
||||||
qs_np_id = qs_np.copy()
|
qs_np_id = qs_np.copy()
|
||||||
b = np.ones(qs_np_id.shape[0])
|
b = np.ones(qs_np_id.shape[0])
|
||||||
qs_np_id = np.column_stack((qs_np_id,b))
|
qs_np_id = np.column_stack((qs_np_id,b))
|
||||||
|
|
@ -486,7 +452,7 @@ class OffPushStreamProcess(PushStreamProcess):
|
||||||
if q[11] >= 1:
|
if q[11] >= 1:
|
||||||
cls = int(q[9])
|
cls = int(q[9])
|
||||||
if not (cls in new_lab):
|
if not (cls in new_lab):
|
||||||
continue # 为了防止其他类别被带出
|
continue # 为了防止其他类别被带出
|
||||||
code = str(int(q[10])).zfill(3)
|
code = str(int(q[10])).zfill(3)
|
||||||
if det_xywh2.get(code) is None:
|
if det_xywh2.get(code) is None:
|
||||||
det_xywh2[code] = {}
|
det_xywh2[code] = {}
|
||||||
|
|
@ -499,13 +465,6 @@ class OffPushStreamProcess(PushStreamProcess):
|
||||||
is_new = False
|
is_new = False
|
||||||
if q[11] == 1:
|
if q[11] == 1:
|
||||||
is_new = True
|
is_new = True
|
||||||
|
|
||||||
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
|
||||||
cls = ocrlabel
|
|
||||||
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
|
||||||
cls = crowdlabel
|
|
||||||
label_array = points
|
|
||||||
|
|
||||||
if cd is None:
|
if cd is None:
|
||||||
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
|
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,10 @@ service:
|
||||||
# 2 模型追踪
|
# 2 模型追踪
|
||||||
model_type: 1
|
model_type: 1
|
||||||
limit: 3
|
limit: 3
|
||||||
|
# 新增:大模型识别配置
|
||||||
|
llm:
|
||||||
|
server_ip: "192.168.10.11"
|
||||||
|
api_url: "http://192.168.10.11:8000/generate"
|
||||||
task:
|
task:
|
||||||
# 任务限制5个
|
# 任务限制5个
|
||||||
limit: 5
|
limit: 5
|
||||||
|
|
@ -36,4 +40,3 @@ service:
|
||||||
mqtt_flag: 0
|
mqtt_flag: 0
|
||||||
#是否启用alg控制功能
|
#是否启用alg控制功能
|
||||||
algSwitch: False
|
algSwitch: False
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue