update yolov26

This commit is contained in:
2026-01-30 12:08:36 +08:00
parent 99b2a40035
commit c01b1f41be
4 changed files with 95 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
import os
import sys
import subprocess
import time
import cv2
import numpy as np
from pathlib import Path
@@ -14,7 +15,7 @@ except ImportError:
sys.exit(1)
class VideoCleaner:
def __init__(self, model_path='yolov8n.pt', brightness_threshold=25, age_days=30):
def __init__(self, model_path='yolo26n.pt', brightness_threshold=25, age_days=30):
print(f"Initializing YOLO model: {model_path}...")
try:
self.model = YOLO(model_path)
@@ -87,8 +88,8 @@ class VideoCleaner:
# Following your rules: "If it's night and no lights, delete".
# So we only need to detect humans to justify keeping the video.
small_frame = cv2.resize(frame, (640, 360))
results = self.model(small_frame, classes=[0], verbose=False, conf=0.5)
debugmode=False
results = self.model(small_frame, classes=[0], verbose=False, conf=0.7)
debugmode=True
if len(results[0].boxes) > 0:
if is_color:
# --- DEBUG: Save the frame that triggered detection ---
@@ -119,7 +120,7 @@ class VideoCleaner:
video_path = Path(video_path).resolve()
mtime = datetime.fromtimestamp(os.path.getmtime(video_path))
if datetime.now() - mtime < self.age_limit:
return
return False # 表示因为时间太新没处理
keep, reason = self.should_keep_video(video_path)
if keep:
@@ -128,6 +129,7 @@ class VideoCleaner:
else:
print(f"Action: DELETE {video_path.name} - Reason: {reason}")
os.remove(video_path)
return True # 表示处理了
def move_to_processed(self, video_path, processed_base_dir, input_base_dir):
rel_path = video_path.relative_to(input_base_dir)
@@ -140,17 +142,43 @@ class VideoCleaner:
input_path = Path(input_dir).resolve()
if not input_path.exists(): return
processed_dir = input_path.parent / "processed"
for root, dirs, files in os.walk(input_path):
if "processed" in dirs: dirs.remove("processed")
for file in files:
if file.lower().endswith(self.supported_extensions):
self.process_video_file(Path(root) / file, processed_dir, input_path)
print(f"Scanning {input_path}...")
while True:
all_videos = []
# 每次循环都获取最新列表
for root, dirs, files in os.walk(input_path):
if "processed" in dirs: dirs.remove("processed")
for file in files:
if file.lower().endswith(self.supported_extensions):
full_path = Path(root) / file
all_videos.append(full_path)
if not all_videos:
print("No more files to process. Exiting.")
break
# 按修改时间排序,取最旧的一个
all_videos.sort(key=lambda x: os.path.getmtime(x))
processed_in_this_loop = False
for target_file in all_videos:
if self.process_video_file(target_file, processed_dir, input_path):
processed_in_this_loop = True
break # 处理了一个,重新获取列表
if not processed_in_this_loop:
# 如果列表里剩下的所有文件都还没到 30 天,那就退出
print("All remaining files are newer than the age limit. Exiting.")
break
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("dir", help="Target directory")
parser.add_argument("--days", type=int, default=30)
parser.add_argument("--model", type=str, default='yolo26n.pt', help="Path to YOLO model or model name")
args = parser.parse_args()
cleaner = VideoCleaner(age_days=args.days)
cleaner = VideoCleaner(model_path=args.model, age_days=args.days)
cleaner.scan_and_process(args.dir)