I am an open cv beginner. I followed the steps in this tutorial to practice using it. http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html#display-video
I changed some lines for performance on my mac:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
size = (int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)),
int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)))
# Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC(*'DIVX') # upper case - yl3
out = cv2.VideoWriter('output.avi',fourcc, 20, size, 1) #20.0: number of frames per sec
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,1)
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
I am using Python 2.7.10, opencv 2.4.12 and mac OS X 10.10.5
Now I can successfully get the camera to work and generate an output.avi
file in the same directory, but the file was only 414k overtime and I can't open it. It seemed that it contained nothing but black.
Can anyone help me with that?