How to read/write video with OpenCV in Python?
I want to create a small test application, and I need to input/output video with OpenCV Python API. How can I do that?
I want to create a small test application, and I need to input/output video with OpenCV Python API. How can I do that?
Here is a minimal example:
import cv2
capture = cv2.VideoCapture("video.avi")
while True:
ret, img = capture.read()
result = processFrame(img)
cv2.imshow('some', result)
if 0xFF & cv2.waitKey(5) == 27:
break
cv2.destroyAllWindows()
Does this still stand with the newest versions of opencv and python? (python 3.6.1 64 bit and opencv 3.2)
yes it will work for updated versions also and you can try like this also. import cv2 import numpy as np
cap = cv2.VideoCapture("challenge.mp4") # if you are giving camera as input then give (0) to videoCapture. while(cap.isOpened()):
# Take each frame
ret, image = cap.read()
if ret:
# do operations on image as per your application
else:
cap.set(cv2.CAP_PROP_POS_FRAMES,0)
cv2.imshow('img',image)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cap.release() cv2.destroyAllWindows()
this all things you can get directly from opencv tutorial... try @Kirill
Asked: 2012-06-08 08:50:21 -0600
Seen: 10,140 times
Last updated: Mar 05 '18