Spaces:
Sleeping
Sleeping
gradio opencv debugging
Browse files- gradio_utils.py +46 -0
gradio_utils.py
CHANGED
|
@@ -40,14 +40,60 @@ def load_model(model_configs, device="cpu"):
|
|
| 40 |
|
| 41 |
def extract_frames(video_path):
|
| 42 |
"""Extracts frames from a video file."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
vidcap = cv2.VideoCapture(video_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
frames = []
|
|
|
|
| 45 |
success, image = vidcap.read()
|
|
|
|
|
|
|
|
|
|
| 46 |
while success:
|
| 47 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 48 |
frames.append(image_rgb)
|
| 49 |
success, image = vidcap.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
vidcap.release()
|
|
|
|
|
|
|
| 51 |
return frames
|
| 52 |
|
| 53 |
|
|
|
|
| 40 |
|
| 41 |
def extract_frames(video_path):
|
| 42 |
"""Extracts frames from a video file."""
|
| 43 |
+
import os
|
| 44 |
+
|
| 45 |
+
# Debug: Check if file exists and get info
|
| 46 |
+
print(f"π DEBUG: Attempting to extract frames from: {video_path}")
|
| 47 |
+
print(f"π DEBUG: File exists: {os.path.exists(video_path)}")
|
| 48 |
+
|
| 49 |
+
if os.path.exists(video_path):
|
| 50 |
+
file_size = os.path.getsize(video_path)
|
| 51 |
+
print(f"π DEBUG: File size: {file_size} bytes")
|
| 52 |
+
print(f"π DEBUG: File permissions: {oct(os.stat(video_path).st_mode)}")
|
| 53 |
+
else:
|
| 54 |
+
print(f"β DEBUG: File does not exist at path: {video_path}")
|
| 55 |
+
return []
|
| 56 |
+
|
| 57 |
+
# Debug: Try to open with OpenCV
|
| 58 |
+
print(f"π DEBUG: Creating VideoCapture object...")
|
| 59 |
vidcap = cv2.VideoCapture(video_path)
|
| 60 |
+
|
| 61 |
+
# Debug: Check if VideoCapture opened successfully
|
| 62 |
+
is_opened = vidcap.isOpened()
|
| 63 |
+
print(f"π DEBUG: VideoCapture opened successfully: {is_opened}")
|
| 64 |
+
|
| 65 |
+
if not is_opened:
|
| 66 |
+
print(f"β DEBUG: Failed to open video with OpenCV")
|
| 67 |
+
vidcap.release()
|
| 68 |
+
return []
|
| 69 |
+
|
| 70 |
+
# Debug: Get video properties
|
| 71 |
+
frame_count = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 72 |
+
fps = vidcap.get(cv2.CAP_PROP_FPS)
|
| 73 |
+
width = int(vidcap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 74 |
+
height = int(vidcap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 75 |
+
|
| 76 |
+
print(f"π DEBUG: Video properties - Frames: {frame_count}, FPS: {fps}, Size: {width}x{height}")
|
| 77 |
+
|
| 78 |
frames = []
|
| 79 |
+
frame_index = 0
|
| 80 |
success, image = vidcap.read()
|
| 81 |
+
|
| 82 |
+
print(f"π DEBUG: First frame read success: {success}")
|
| 83 |
+
|
| 84 |
while success:
|
| 85 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 86 |
frames.append(image_rgb)
|
| 87 |
success, image = vidcap.read()
|
| 88 |
+
frame_index += 1
|
| 89 |
+
|
| 90 |
+
# Debug: Log progress every 10 frames
|
| 91 |
+
if frame_index % 10 == 0:
|
| 92 |
+
print(f"π DEBUG: Extracted {frame_index} frames so far...")
|
| 93 |
+
|
| 94 |
vidcap.release()
|
| 95 |
+
|
| 96 |
+
print(f"β
DEBUG: Successfully extracted {len(frames)} frames from video")
|
| 97 |
return frames
|
| 98 |
|
| 99 |
|