(p, frame_interval=1)
| 367 | return pts3ds_other, colors, conf_other, cam_dict |
| 368 | |
| 369 | def parse_seq_path(p, frame_interval=1): |
| 370 | global framerate |
| 371 | |
| 372 | if os.path.isdir(p): |
| 373 | all_img_paths = sorted(glob.glob(f"{p}/*")) |
| 374 | img_extensions = {'.jpg', '.jpeg', '.png', '.bmp', '.tiff', '.tif', '.webp'} |
| 375 | img_paths = [path for path in all_img_paths |
| 376 | if os.path.splitext(path.lower())[1] in img_extensions] |
| 377 | |
| 378 | if not img_paths: |
| 379 | raise ValueError(f"No image files found in directory {p}") |
| 380 | |
| 381 | if frame_interval > 1: |
| 382 | img_paths = img_paths[::frame_interval] |
| 383 | print(f" - Image sequence: Total images: {len(all_img_paths)}, " |
| 384 | f"Frame interval: {frame_interval}, Images to process: {len(img_paths)}") |
| 385 | |
| 386 | framerate = 30.0 / frame_interval |
| 387 | |
| 388 | tmpdirname = None |
| 389 | else: |
| 390 | cap = cv2.VideoCapture(p) |
| 391 | if not cap.isOpened(): |
| 392 | raise ValueError(f"Error opening video file {p}") |
| 393 | video_fps = cap.get(cv2.CAP_PROP_FPS) |
| 394 | total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) |
| 395 | if video_fps == 0: |
| 396 | cap.release() |
| 397 | raise ValueError(f"Error: Video FPS is 0 for {p}") |
| 398 | |
| 399 | framerate = video_fps / frame_interval |
| 400 | |
| 401 | frame_indices = list(range(0, total_frames, frame_interval)) |
| 402 | print( |
| 403 | f" - Video FPS: {video_fps}, Frame Interval: {frame_interval}, Total Frames to Read: {len(frame_indices)}, Processed Framerate: {framerate}" |
| 404 | ) |
| 405 | img_paths = [] |
| 406 | tmpdirname = tempfile.mkdtemp() |
| 407 | for i in frame_indices: |
| 408 | cap.set(cv2.CAP_PROP_POS_FRAMES, i) |
| 409 | ret, frame = cap.read() |
| 410 | if not ret: |
| 411 | break |
| 412 | frame_path = os.path.join(tmpdirname, f"frame_{i}.jpg") |
| 413 | cv2.imwrite(frame_path, frame) |
| 414 | img_paths.append(frame_path) |
| 415 | cap.release() |
| 416 | return img_paths, tmpdirname |
| 417 | |
| 418 | |
| 419 | def run_inference(args): |
no test coverage detected