From 112aace08718ad0ead624286fe09e4bf941dee5a Mon Sep 17 00:00:00 2001
From: zhm <839713154@qq.com>
Date: 星期五, 25 七月 2025 14:16:33 +0800
Subject: [PATCH] 预警跟图片描述修改--修改检测内容
---
qwen_detect.py | 95 ++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 80 insertions(+), 15 deletions(-)
diff --git a/qwen_detect.py b/qwen_detect.py
index 871f5da..ed9c8f8 100644
--- a/qwen_detect.py
+++ b/qwen_detect.py
@@ -9,7 +9,8 @@
from pymilvus import connections, Collection
from logging.handlers import RotatingFileHandler
import get_mem
-from multiprocessing import Process
+from qwen_thread_description import qwen_thread_description
+
class ThreadPool:
def __init__(self):
@@ -60,8 +61,10 @@
# 鍔犺浇闆嗗悎
self.collection = Collection(name="smartobject")
self.collection.load()
- #鍒涘缓qwen绾跨▼姹�
- self.pool = qwen_thread(self.config,self.logger)
+ #鍒涘缓qwen绾跨▼姹�--棰勮绾跨▼姹�
+ self.poolWarning = qwen_thread(self.config,self.logger)
+ # 鍒涘缓qwen绾跨▼姹�--鍥剧墖鎻忚堪绛�
+ self.poolDescription= qwen_thread_description(self.config, self.logger)
#鏄惁鏇存柊
self._isupdate = False
@@ -88,12 +91,69 @@
self.threads[camera_id] = t
return t
- # 鍚姩绾跨▼浠诲姟
+ # 鍚姩绾跨▼浠诲姟--棰勮
+ def workerWarning(self, camera_id):
+ while True:
+ try:
+ res_a = self.collection.query(
+ expr=f"is_desc == 0 and video_point_id=={camera_id}",
+ output_fields=["id", "zh_desc_class", "text_vector", "bounding_box", "video_point_name",
+ "task_id",
+ "task_name", "event_level_id", "event_level_name",
+ "video_point_id", "detect_num", "is_waning", "is_desc", "waning_value",
+ "rule_id",
+ "detect_id", "knowledge_id", "suggestion", "risk_description",
+ "detect_time", "image_path", "image_desc_path", "video_path"],
+ consistency_level="Strong",
+ order_by_field="id", # 鎸塱d瀛楁鎺掑簭
+ order_by_type="desc" # 闄嶅簭鎺掑垪
+ )
+ # 璇诲彇鍏变韩鍐呭瓨涓殑鍥剧墖
+ # image_id = get_mem.smem_read_frame_qianwen(camera_id)
+ if len(res_a) > 0:
+ # sorted_results = sorted(res_a, key=itemgetter("id"), reverse=True)
+ # res = sorted_results[0]
+ res = max(res_a, key=itemgetter("id"))
+ self.collection.delete(f"id == {res['id']}")
+ # 鏁版嵁缁�
+ data = {
+ "event_level_id": res['event_level_id'], # event_level_id
+ "event_level_name": res['event_level_name'], # event_level_id
+ "rule_id": res["rule_id"],
+ "video_point_id": res['video_point_id'], # video_point_id
+ "video_point_name": res['video_point_name'],
+ "is_waning": 0,
+ "is_desc":4,#棰勮涓姸鎬�
+ "zh_desc_class": res['zh_desc_class'],
+ "bounding_box": res['bounding_box'], # bounding_box
+ "task_id": res['task_id'], # task_id
+ "task_name": res['task_name'], # task_id
+ "detect_id": res['detect_id'], # detect_id
+ "detect_time": res['detect_time'], # detect_time
+ "detect_num": res['detect_num'],
+ "waning_value": res['waning_value'],
+ "image_path": res['image_path'], # image_path
+ "image_desc_path": res['image_desc_path'], # image_desc_path
+ "video_path": res['video_path'],
+ "text_vector": res['text_vector'],
+ "risk_description": res['risk_description'],
+ "suggestion": res['suggestion'],
+ "knowledge_id": res['knowledge_id']
+ }
+ # 淇濆瓨鍒癿ilvus
+ image_id = self.collection.insert(data).primary_keys
+ res['id'] = image_id[0]
+ self.poolWarning.submit(res)
+ time_sel.sleep(0.01)
+ except Exception as e:
+ logging.info(f"{camera_id}绾跨▼閿欒:{e}")
+
+ # 鍚姩绾跨▼浠诲姟--鐢熸垚鍥剧墖鎻忚堪绛�
def worker(self, camera_id):
while True:
try:
res_a = self.collection.query(
- expr=f"is_desc == 0 and video_point_id=={camera_id}",
+ expr=f"is_desc == 5 and video_point_id=={camera_id}",
output_fields=["id", "zh_desc_class", "text_vector", "bounding_box", "video_point_name", "task_id",
"task_name", "event_level_id", "event_level_name",
"video_point_id", "detect_num", "is_waning", "is_desc", "waning_value", "rule_id",
@@ -106,8 +166,9 @@
# 璇诲彇鍏变韩鍐呭瓨涓殑鍥剧墖
# image_id = get_mem.smem_read_frame_qianwen(camera_id)
if len(res_a) > 0:
- sorted_results = sorted(res_a, key=itemgetter("id"), reverse=True)
- res = sorted_results[0]
+ #sorted_results = sorted(res_a, key=itemgetter("id"), reverse=True)
+ #res = sorted_results[0]
+ res = max(res_a, key=itemgetter("id"))
self.collection.delete(f"id == {res['id']}")
# 鏁版嵁缁�
data = {
@@ -116,9 +177,9 @@
"rule_id": res["rule_id"],
"video_point_id": res['video_point_id'], # video_point_id
"video_point_name": res['video_point_name'],
- "is_waning": 0,
+ "is_waning": res['is_waning'],
"is_desc": 1,
- "zh_desc_class": "",
+ "zh_desc_class": res['zh_desc_class'],
"bounding_box": res['bounding_box'], # bounding_box
"task_id": res['task_id'], # task_id
"task_name": res['task_name'], # task_id
@@ -137,7 +198,7 @@
# 淇濆瓨鍒癿ilvus
image_id = self.collection.insert(data).primary_keys
res['id'] = image_id[0]
- self.pool.submit(res)
+ self.poolDescription.submit(res)
time_sel.sleep(0.01)
except Exception as e:
logging.info(f"{camera_id}绾跨▼閿欒:{e}")
@@ -180,11 +241,11 @@
def shutdown_all(self) -> None:
"""娓呯悊鎵�鏈夌嚎绋�"""
- with self.lock:
- for camera_id, thread in list(self.threads.items()):
- if thread.is_alive():
- thread.join(timeout=1)
- del self.threads[camera_id]
+ for camera_id, thread in list(self.threads.items()):
+ if thread.is_alive():
+ thread.join(timeout=1)
+ del self.threads[camera_id]
+
#鑾峰彇浠诲姟
def getTaskconf(self,isupdate):
@@ -226,6 +287,9 @@
thread = pool.threads.get(camera.get("camera_id"))
if not thread:
logging.info(f"寮�濮嬪垱寤簕camera.get('camera_id')}绾跨▼")
+ #鍏堝鏁版嵁杩涜棰勮
+ pool.safe_start(pool.workerWarning, camera.get('camera_id'))
+ #鍦ㄧ敓鎴愬浘鐗囨弿杩般�佸鐞嗗缓璁瓑淇℃伅
pool.safe_start(pool.worker, camera.get('camera_id'))
logging.info(f"{camera.get('camera_id')}绾跨▼鍒涘缓瀹屾瘯")
@@ -237,6 +301,7 @@
thread = pool.threads.get(camera.get("camera_id"))
if not thread:
logging.info(f"寮�濮嬪垱寤簕camera.get('camera_id')}绾跨▼")
+ pool.safe_start(pool.workerWarning, camera.get('camera_id'))
pool.safe_start(pool.worker, camera.get('camera_id'))
logging.info(f"{camera.get('camera_id')}绾跨▼鍒涘缓瀹屾瘯")
--
Gitblit v1.8.0