Skip to content

Instantly share code, notes, and snippets.

@alexanderkoumis
Created October 28, 2015 22:07
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 alexanderkoumis/10bd5a48caa143108ded to your computer and use it in GitHub Desktop.
Save alexanderkoumis/10bd5a48caa143108ded to your computer and use it in GitHub Desktop.
import cv2
import sys
def run(video_path):
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print video_path, 'doesn\'t exist'
sys.exit()
frame_num_curr = int(cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES))
frame_num_total = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
while True:
flag, frame_bgr = cap.read()
if flag:
frame_num_curr = int(cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES))
process(frame_bgr, frame_num_curr, frame_num_total)
if frame_num_curr == frame_num_total:
break
else:
print 'Error reading frame'
print 'Read all images'
def process(frame, frame_num_curr, frame_num_total):
cv2.imshow('lol', frame)
cv2.waitKey(33)
if __name__ == '__main__':
run(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment