Browse Source

refactor(panorama): 移除人体跟踪器相关代码,优化模块结构

- 删除 PersonTracker 类及相关代码内容
- 保留并整理全景摄像头及物体检测核心逻辑
- 统一代码风格和注释格式
- 减少模块冗余,提高维护性和可读性
wenhongquan 3 ngày trước cách đây
mục cha
commit
50cbf1406b

+ 14 - 8
dual_camera_system/panorama_camera.py

@@ -540,7 +540,7 @@ class ObjectDetector:
     
     def _save_detection_image(self, frame: np.ndarray, detections: List[DetectedObject]):
         """
-        保存带有检测标记的图片(只标记人体,序号从0开始
+        保存带有检测标记的图片(只对超过置信度阈值的人编号
         Args:
             frame: 原始图像
             detections: 检测结果列表
@@ -557,23 +557,29 @@ class ObjectDetector:
             # 复制图像避免修改原图
             marked_frame = frame.copy()
             
-            # 只统计人,序号从0开始
+            # 置信度阈值(人员检测用更高阈值)
+            person_threshold = self.config.get('person_threshold', 0.8)
+            conf_threshold = self.config.get('confidence_threshold', 0.5)
+            
+            # 只对超过置信度阈值的人编号
             person_count = 0
             
             for det in detections:
                 x, y, w, h = det.bbox
                 
-                # 只对人标记序号
                 is_person = det.class_name in ['person', '人']
                 box_color = (0, 255, 0) if is_person else (255, 165, 0)  # 绿色/橙色
                 
                 # 绘制边界框
                 cv2.rectangle(marked_frame, (x, y), (x + w, y + h), box_color, 2)
                 
-                # 标签:人用序号,其他显示类别名
+                # 标签:人且超过阈值才编号,其他显示类别名
                 if is_person:
-                    label = f"person_{person_count}"
-                    person_count += 1
+                    if det.confidence >= person_threshold:
+                        label = f"person_{person_count}"
+                        person_count += 1
+                    else:
+                        label = f"person({det.confidence:.2f})"  # 未达阈值,显示置信度
                 else:
                     label = det.class_name
                 
@@ -598,7 +604,7 @@ class ObjectDetector:
                 )
             
             
-            # 生成文件名(时间戳+人数)
+            # 生成文件名(时间戳+有效人数)
             timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
             filename = f"panorama_{timestamp}_n{person_count}.jpg"
             filepath = self._image_save_dir / filename
@@ -607,7 +613,7 @@ class ObjectDetector:
             cv2.imwrite(str(filepath), marked_frame, [cv2.IMWRITE_JPEG_QUALITY, 90])
             self._last_save_time = current_time
             
-            logger.info(f"[全景] 已保存检测图片: {filepath},检测到 {len(detections)} 人")
+            logger.info(f"[全景] 已保存检测图片: {filepath},有效人数 {person_count} (阈值={person_threshold})")
             
             # 定期清理旧图片
             self._cleanup_old_images()

+ 16 - 8
dual_camera_system/ptz_person_tracker.py

@@ -283,7 +283,7 @@ class PTZPersonDetector:
     
     def _save_detection_image(self, frame: np.ndarray, persons: List[DetectedPerson]):
         """
-        保存带有检测标记的图片(序号从0开始
+        保存带有检测标记的图片(只对超过置信度阈值的人编号
         Args:
             frame: 原始图像
             persons: 检测到的人体列表
@@ -300,15 +300,23 @@ class PTZPersonDetector:
             # 复制图像避免修改原图
             marked_frame = frame.copy()
             
-            # 绘制检测结果(序号从0开始)
-            for idx, person in enumerate(persons):
+            # 只对超过置信度阈值的人编号
+            person_count = 0
+            
+            for person in persons:
                 x1, y1, x2, y2 = person.bbox
                 
                 # 绘制边界框(绿色)
                 cv2.rectangle(marked_frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
                 
-                # 绘制序号标签:person_0, person_1, ...
-                label = f"person_{idx}"
+                # 标签:超过阈值才编号
+                if person.confidence >= self.confidence_threshold:
+                    label = f"person_{person_count}"
+                    person_count += 1
+                else:
+                    label = f"person({person.confidence:.2f})"  # 未达阈值,显示置信度
+                
+                
                 (label_w, label_h), baseline = cv2.getTextSize(
                     label, cv2.FONT_HERSHEY_SIMPLEX, 0.8, 2
                 )
@@ -329,16 +337,16 @@ class PTZPersonDetector:
                 )
             
             
-            # 生成文件名(时间戳+人数)
+            # 生成文件名(时间戳+有效人数)
             timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
-            filename = f"ptz_{timestamp}_n{len(persons)}.jpg"
+            filename = f"ptz_{timestamp}_n{person_count}.jpg"
             filepath = self._image_save_dir / filename
             
             # 保存图片
             cv2.imwrite(str(filepath), marked_frame, [cv2.IMWRITE_JPEG_QUALITY, 90])
             self._last_save_time = current_time
             
-            logger.info(f"[球机] 已保存检测图片: {filepath},检测到 {len(persons)} 人")
+            logger.info(f"[球机] 已保存检测图片: {filepath},有效人数 {person_count} (阈值={self.confidence_threshold})")
             
         except Exception as e:
             logger.error(f"[球机] 保存检测图片失败: {e}")