Skip to content

Instantly share code, notes, and snippets.

@kunalgoyal9
Last active July 15, 2020 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunalgoyal9/6753d605d136286379765e2f911acb53 to your computer and use it in GitHub Desktop.
Save kunalgoyal9/6753d605d136286379765e2f911acb53 to your computer and use it in GitHub Desktop.
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