produce preview picture
This commit is contained in:
@@ -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,16 +93,22 @@ class VideoCleaner:
|
||||
if len(results[0].boxes) > 0:
|
||||
if is_color:
|
||||
# --- DEBUG: Save the frame that triggered detection ---
|
||||
if debugmode :
|
||||
if debugmode or save_preview_path:
|
||||
# Draw boxes on the frame for visualization
|
||||
annotated_frame = results[0].plot()
|
||||
|
||||
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"
|
||||
|
||||
# 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 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)
|
||||
|
||||
Reference in New Issue
Block a user