Ask Your Question

JBR's profile - activity

2016-07-12 12:58:02 -0600 asked a question Video saved by opencv is zero bytes

HI I followed the getting started guide and got the following code now:

import numpy as np
import cv2

cap = cv2.VideoCapture(0) #initialize the camera
out = cv2.VideoWriter('output.avi',-1, 20.0, (640,480)) #Define the codec and create VideoWriter object

while(cap.isOpened()):
    ret, frame = cap.read() #read frame
    if ret == True:
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        out.write(frame) #write frame to output 
        cv2.imshow('frame',frame) #show frame
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

the problem is that as soon as i hit the q button and try to watch my saved file i cant ebcasue it is 0 bytes big. WHy is that? Everything else works, i can see the video in the video frame but it simply doesnt save it.

Im using anaconda with python 2 and opencv 2 as well (newest of each).

thanks