Skip to content

Instantly share code, notes, and snippets.

@garybradski
Created September 22, 2017 21:56
Show Gist options
  • Save garybradski/31a82958d67b130fdce2fbe592684156 to your computer and use it in GitHub Desktop.
Save garybradski/31a82958d67b130fdce2fbe592684156 to your computer and use it in GitHub Desktop.
Just reading a movie with opencv in python, jumping to a frame and displaying
cap = cv2.VideoCapture('/opt/home/garybradski/data/matte_this/shot02/Tornado.mp4')
length = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
print "len Tornado = ", length
cv2.namedWindow('Tornado', cv2.WINDOW_NORMAL)
cv2.resizeWindow('Tornado',960,540)
# seek
assert cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 8000)
n = 0
wait_key = 30
while True:
ret, frame = cap.read()
if n > length:
break
if not ret:
break
cv2.imshow('Tornado', frame)
#key handling
k = cv2.waitKey(wait_key) & 0xff
if chr(k) == 'r': #start running
wait_key = 30
elif chr(k) == 'p': #pause between frames
wait_key = 0
elif k == 27: #end processing
break
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment