From b0567158be678956ab35e64f7e71d2ff2aed28ce Mon Sep 17 00:00:00 2001 From: Shuming Liu Date: Fri, 30 Jan 2026 14:48:27 +0800 Subject: [PATCH] produce preview picture --- video_cleaner.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/video_cleaner.py b/video_cleaner.py index e1e346c..5643bda 100644 --- a/video_cleaner.py +++ b/video_cleaner.py @@ -42,7 +42,7 @@ class VideoCleaner: return True - def should_keep_video(self, video_path): + def should_keep_video(self, video_path, save_preview_path=None): """ Scans the video to see if it should be kept. Kept if: (It's not a night-only video) AND (Human is detected). @@ -93,15 +93,21 @@ class VideoCleaner: if len(results[0].boxes) > 0: if is_color: # --- DEBUG: Save the frame that triggered detection --- - if debugmode : - debug_dir = Path("debug_detections") - debug_dir.mkdir(exist_ok=True) - debug_filename = debug_dir / f"detected_{video_path.stem}_frame_{i}.jpg" - + if debugmode or save_preview_path: # Draw boxes on the frame for visualization annotated_frame = results[0].plot() - cv2.imwrite(str(debug_filename), annotated_frame) - print(f"DEBUG: Saved detection image to {debug_filename}") + + if debugmode: + debug_dir = Path("debug_detections") + debug_dir.mkdir(exist_ok=True) + debug_filename = debug_dir / f"detected_{video_path.stem}_frame_{i}.jpg" + cv2.imwrite(str(debug_filename), annotated_frame) + print(f"DEBUG: Saved detection image to {debug_filename}") + + if save_preview_path: + save_preview_path.parent.mkdir(parents=True, exist_ok=True) + cv2.imwrite(str(save_preview_path), annotated_frame) + print(f"INFO: Saved preview image to {save_preview_path}") cap.release() return True, "Human detected in color mode" @@ -122,7 +128,12 @@ class VideoCleaner: if datetime.now() - mtime < self.age_limit: return False # 表示因为时间太新没处理 - keep, reason = self.should_keep_video(video_path) + # Calculate target path for preview image + rel_path = video_path.relative_to(input_base_dir) + output_path = processed_base_dir / rel_path + preview_path = output_path.with_suffix('.jpg') + + keep, reason = self.should_keep_video(video_path, save_preview_path=preview_path) if keep: print(f"Action: KEEP {video_path.name} - Reason: {reason}") self.move_to_processed(video_path, processed_base_dir, input_base_dir)