diff --git a/apps/ecm/service.py b/apps/ecm/service.py index 106a01c9..56f3d63a 100644 --- a/apps/ecm/service.py +++ b/apps/ecm/service.py @@ -642,10 +642,3 @@ def snap_and_analyse(vchannel: TDevice, algo_codes: list, opl: Opl = None): }) if event: notify_event(event) - - -def loop_and_analyse(vchannel: TDevice, algo_codes: list, opl: Opl = None): - # 启动rtsp轮询进行算法识别 - pass - # cates = EventCate.objects.filter(loop_on=True, self_algo=True) - # AlgoChannel.objects.filter(algo__loop_on=True, algo__self_algo=True).values('algo__code', 'vchannel') diff --git a/apps/ecm/tasks.py b/apps/ecm/tasks.py index 698e167b..f596fa47 100644 --- a/apps/ecm/tasks.py +++ b/apps/ecm/tasks.py @@ -117,3 +117,45 @@ def opl_task(vc_codes: list, opl_id: str): time.sleep(10) opl.mtask_uid = None opl.save() + + +@shared_task(base=CustomTask) +def monitor_and_analyse(vchannel_code: str, algo_codes: list): + """rtsp流监控进行算法识别 + + Args: + vchannel_code (str): 视频通道编号 + algo_codes (list): 算法代号 + """ + # cates = EventCate.objects.filter(loop_on=True, self_algo=True) + # AlgoChannel.objects.filter(algo__loop_on=True, algo__self_algo=True).values('algo__code', 'vchannel') + import cv2 + # RTSP URL + rtsp_url = dhClient.get_rtsp(vchannel_code) + # 打开RTSP流 + cap = cv2.VideoCapture(rtsp_url) + # 检查是否成功打开 + if not cap.isOpened(): + print("Error opening video stream or file") + + # 循环读取帧 + while cap.isOpened(): + ret, frame = cap.read() + + if not ret: + break + + # 在这里可以对每一帧进行处理 + + # 显示帧 + cv2.namedWindow("Frame", 0) + cv2.resizeWindow("Frame", 1600, 900) + cv2.imshow("Frame", frame) + + # 按 'q' 键退出 + if cv2.waitKey(1) & 0xFF == ord('q'): + break + + # 释放资源 + cap.release() + cv2.destroyAllWindows() \ No newline at end of file