Przeglądaj źródła

fix(dual_camera): 修复FFmpeg多线程崩溃问题并添加校准支持

设置OPENCV_FFMPEG_CAPTURE_OPTIONS环境变量以避免多线程解码崩溃
在PTZ跟踪逻辑中添加校准转换支持,当启用校准时使用校准后的坐标
wenhongquan 4 dni temu
rodzic
commit
6e23739919
2 zmienionych plików z 15 dodań i 2 usunięć
  1. 11 2
      dual_camera_system/coordinator.py
  2. 4 0
      dual_camera_system/main.py

+ 11 - 2
dual_camera_system/coordinator.py

@@ -351,7 +351,12 @@ class Coordinator:
                         should_move = False
                 
                 if should_move:
-                    self.ptz.track_target(x_ratio, y_ratio)
+                    if self.enable_calibration and self.calibrator and self.calibrator.is_calibrated():
+                        pan, tilt = self.calibrator.transform(x_ratio, y_ratio)
+                        zoom = self.ptz.ptz_config.get('default_zoom', 8)
+                        self.ptz.goto_exact_position(pan, tilt, zoom)
+                    else:
+                        self.ptz.track_target(x_ratio, y_ratio)
                     self.last_ptz_position = (x_ratio, y_ratio)
             
             # 执行OCR识别 (仅在 OCR 启用时)
@@ -473,7 +478,11 @@ class Coordinator:
             zoom: 变倍
         """
         if self.enable_ptz_tracking and self.enable_ptz_camera:
-            self.ptz.move_to_target(x_ratio, y_ratio, zoom)
+            if self.enable_calibration and self.calibrator and self.calibrator.is_calibrated():
+                pan, tilt = self.calibrator.transform(x_ratio, y_ratio)
+                self.ptz.goto_exact_position(pan, tilt, zoom or self.ptz.ptz_config.get('default_zoom', 8))
+            else:
+                self.ptz.move_to_target(x_ratio, y_ratio, zoom)
     
     def capture_snapshot(self) -> Optional[np.ndarray]:
         """

+ 4 - 0
dual_camera_system/main.py

@@ -7,7 +7,11 @@
 3. 对人体进行分割并OCR识别衣服上的编号
 """
 
+# 必须在import cv2之前设置,否则FFmpeg多线程解码会导致
+# "Assertion fctx->async_lock failed at pthread_frame.c:167" 崩溃
 import os
+os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'threads;1'
+
 import sys
 import time
 import argparse