Last active
July 15, 2020 08:47
-
-
Save kunalgoyal9/6753d605d136286379765e2f911acb53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import os | |
frames_path = "/home/kunal/Vehicle_detection_tflite/Data-dashboard-Frames" | |
videos_path = "/home/kunal/Vehicle_detection_tflite/Data-dashboard" | |
videos = os.listdir(videos_path) | |
idx = 0 | |
for video in videos: | |
path = os.path.join(videos_path, video) | |
cap = cv2.VideoCapture(path) | |
framerate = int(cap.get(cv2.CAP_PROP_FPS)) | |
framecount = 0 | |
print(framerate) | |
while(True): | |
# Capture frame-by-frame | |
success, image = cap.read() | |
framecount += 1 | |
try: | |
# Check if this is the frame closest to 10 seconds | |
if framecount == (framerate * 2): | |
framecount = 0 | |
idx += 1 | |
cv2.imwrite(os.path.join(frames_path, str(idx) + '.jpg'), image) | |
# exit() | |
# Check end of video | |
if cv2.waitKey(1) & 0xFF == ord('q') or not success: | |
break | |
except Exception as e: | |
print("not done: ", idx, e) | |
#pass | |
cap.release() | |
# cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment