configura fps preview e yolo
This commit is contained in:
@@ -518,6 +518,10 @@ def parse_args():
|
||||
|
||||
ap.add_argument("--preview-width", type=int, default=defaults["preview_width"], help="Larghezza preview")
|
||||
ap.add_argument("--realtime-playback", action="store_true", default=defaults["realtime_playback"], help="Rispetta FPS video")
|
||||
ap.add_argument("--preview-fps", type=float, default=defaults["preview_fps"],
|
||||
help="FPS massimo per lettura/preview realtime. 0 = FPS sorgente")
|
||||
ap.add_argument("--yolo-fps", type=float, default=defaults["yolo_fps"],
|
||||
help="FPS massimo per inferenza YOLO. 0 = ogni frame di preview")
|
||||
ap.add_argument("--max-frames", type=int, default=defaults["max_frames"], help="Numero massimo frame; 0 = tutto")
|
||||
ap.add_argument("--stats-interval", type=float, default=defaults["stats_interval"], help="Intervallo log prestazioni")
|
||||
ap.add_argument("--motion-report-interval", type=int, default=defaults["motion_report_interval"],
|
||||
@@ -557,6 +561,8 @@ def load_navigation_config(path_str: str) -> dict[str, object]:
|
||||
"scan_direction": "destra",
|
||||
"preview_width": 1280,
|
||||
"realtime_playback": True,
|
||||
"preview_fps": 24.0,
|
||||
"yolo_fps": 15.0,
|
||||
"max_frames": 0,
|
||||
"stats_interval": 2.0,
|
||||
"motion_report_interval": 5,
|
||||
@@ -841,7 +847,11 @@ def main() -> int:
|
||||
return 1
|
||||
|
||||
video_fps = cap.get(cv2.CAP_PROP_FPS)
|
||||
frame_delay = 1.0 / video_fps if args.realtime_playback and video_fps and video_fps > 1 else 0.0
|
||||
preview_fps = args.preview_fps if args.preview_fps and args.preview_fps > 0 else video_fps
|
||||
if args.preview_fps and args.preview_fps > 0 and (args.video is None or str(args.video).isdigit()):
|
||||
cap.set(cv2.CAP_PROP_FPS, float(args.preview_fps))
|
||||
frame_delay = 1.0 / preview_fps if args.realtime_playback and preview_fps and preview_fps > 1 else 0.0
|
||||
yolo_interval = 1.0 / args.yolo_fps if args.yolo_fps and args.yolo_fps > 0 else 0.0
|
||||
tracker = LightweightTracker(
|
||||
max_missed=args.max_track_missed,
|
||||
min_match_score=args.min_match_score,
|
||||
@@ -860,6 +870,10 @@ def main() -> int:
|
||||
last_loop_end = start_time
|
||||
yolo_total_ms = 0.0
|
||||
yolo_cycles = 0
|
||||
next_yolo_time = start_time
|
||||
last_yolo_ms = 0.0
|
||||
gaylords: list[Detection] = []
|
||||
tracks: list[Track] = []
|
||||
|
||||
try:
|
||||
while True:
|
||||
@@ -880,25 +894,28 @@ def main() -> int:
|
||||
log(f"Raggiunto --max-frames={args.max_frames}")
|
||||
break
|
||||
|
||||
detections, yolo_ms = detector.detect(frame, args.min_confidence, args.input_size)
|
||||
yolo_total_ms += yolo_ms
|
||||
yolo_cycles += 1
|
||||
gaylords = [
|
||||
det for det in detections
|
||||
if det.class_name.strip().lower() == args.target_class.strip().lower()
|
||||
]
|
||||
|
||||
tracks = tracker.update(gaylords, frame_id, frame.shape[1])
|
||||
if args.motion_report_interval > 0 and frame_id % args.motion_report_interval == 0:
|
||||
navigator.set_motion_text(
|
||||
estimate_motion_from_tracks(tracks, args.motion_min_pixels)
|
||||
)
|
||||
new_snapshots: list[NavigationSnapshot] = []
|
||||
for track in tracks:
|
||||
if track.missed == 0:
|
||||
snapshot = navigator.process_track(track, frame, frame_id, timestamp)
|
||||
if snapshot is not None:
|
||||
new_snapshots.append(snapshot)
|
||||
run_yolo = yolo_interval <= 0 or timestamp >= next_yolo_time
|
||||
if run_yolo:
|
||||
next_yolo_time = timestamp + yolo_interval
|
||||
detections, last_yolo_ms = detector.detect(frame, args.min_confidence, args.input_size)
|
||||
yolo_total_ms += last_yolo_ms
|
||||
yolo_cycles += 1
|
||||
gaylords = [
|
||||
det for det in detections
|
||||
if det.class_name.strip().lower() == args.target_class.strip().lower()
|
||||
]
|
||||
|
||||
tracks = tracker.update(gaylords, frame_id, frame.shape[1])
|
||||
if args.motion_report_interval > 0 and yolo_cycles % args.motion_report_interval == 0:
|
||||
navigator.set_motion_text(
|
||||
estimate_motion_from_tracks(tracks, args.motion_min_pixels)
|
||||
)
|
||||
for track in tracks:
|
||||
if track.missed == 0:
|
||||
snapshot = navigator.process_track(track, frame, frame_id, timestamp)
|
||||
if snapshot is not None:
|
||||
new_snapshots.append(snapshot)
|
||||
if args.no_display and new_snapshots:
|
||||
if args.remote_ack_timeout_sec > 0:
|
||||
time.sleep(args.remote_ack_timeout_sec)
|
||||
@@ -931,6 +948,7 @@ def main() -> int:
|
||||
elapsed = max(time.perf_counter() - start_time, 0.001)
|
||||
fps_text = (
|
||||
f"frame={frame_id} fps={frame_id / elapsed:.1f} "
|
||||
f"yolo_fps={yolo_cycles / elapsed:.1f} yolo={last_yolo_ms:.0f}ms "
|
||||
f"det={len(gaylords)} tracks={len(tracks)} snap={navigator.snapshot_counter}"
|
||||
)
|
||||
display = draw_navigation_debug(
|
||||
|
||||
Reference in New Issue
Block a user