Download utils.py from Yaswanth56/IDSL_road_defect_detection: direct link, hf CLI and curl.
- Browser
- Download file 517 Bytes
-
https://huggingface.co/spaces/Yaswanth56/IDSL_road_defect_detection/resolve/main/utils.py
- Command line
-
hf download hf://spaces/Yaswanth56/IDSL_road_defect_detection/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Yaswanth56/IDSL_road_defect_detection/resolve/main/utils.py
517 Bytes
| import cv2 | |
| from PIL import Image | |
| def extract_frames(video_path, interval=60, max_frames=5): | |
| cap = cv2.VideoCapture(video_path) | |
| frames = [] | |
| idx = 0 | |
| count = 0 | |
| while cap.isOpened() and count < max_frames: | |
| ret, frame = cap.read() | |
| if not ret: | |
| break | |
| if idx % interval == 0: | |
| frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
| frames.append(Image.fromarray(frame_rgb)) | |
| count += 1 | |
| idx += 1 | |
| cap.release() | |
| return frames |