OpenCv - cv2.VideoWriter object has no attribute release

asked 2014-03-29 06:09:04 -0500

Aakash Jolly gravatar image

updated 2014-03-29 06:34:44 -0500

berak gravatar image

I am using OpenCV with python 2.7.3 on Linux 64-bit machine. I wanted to fetch frames from my Logitech C270 and store it as an AVI video. The code is working fine, it also shows me the video getting captured and the output file is also created. But when i try to play the file it is not playing at all as well as i am getting 'cv2.VideoWriter object has no attribute release' error on terminal. So, if someone can tell me how to release the cv2.VideoWriter after completion.

import numpy as np
import cv2

cap = cv2.VideoCapture(1)

fourcc = cv2.cv.CV_FOURCC('X','V','I','D')
out = cv2.VideoWriter('output.avi', fourcc, 20.0,(640,480))

while(True):
    ret, frame = cap.read()
    if cap.isOpened() == 0:
        cap.open(1)

    if ret==True:

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        out.write(gray)
        cv2.imshow('frame',gray)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete