0
import cv
import cv2
cap = cv2.VideoCapture(0)
cap.set(8,100)
out = cv2.VideoWriter('/home/pi/Desktop/output.mp4',cv2.cv.CV_FOURCC('D','I','V','X'),20.0,(640,480))
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)
        out.write(frame)
        cv2.imshow('frame',frame)
        if cv2.waitKey(10) == 27: 
            break
cv2.VideoCapture(0).release()
out.release()
cv2.destroyAllWindows()

This code worked but it never stopped and no video file had been saved. Does anyone know how to solve this? Thanks a lot.

2
  • Do the frames show up on the screen? Are the frames exactly 640x480 pixels? What happened when you pressed Escape? Commented Mar 6, 2014 at 17:35
  • @w.m Sorry i just saw the comment. Yes, the frames showed up on the screen and it was exactly 640*480. When i pressed ESC, an error occurred. It displayed that cv2.VideoWriter object has no attribute 'release' Commented Mar 6, 2014 at 22:19

1 Answer 1

2

Both release() calls can be removed.

cv2.VideoCapture(0).release()

would call release() on a new VideoCapture, what you meant was cap.release().

For the VideoWriter, the release method doesn't exist - you don't have to care about releasing the VideoWriter or VideoCapture in Python. They will be released when their object is destroyed at the end of your program.

Sign up to request clarification or add additional context in comments.

8 Comments

Thank you for answering me. I tried remove this line, but a new error occurs. "object has no attribute 'destroyAllWindows'"
And when I used "DestroyWindow('frame')", it had the same problem.
My spelling mistake. But I typed the right version in my script while having this problem.
And you corrected it to Window_S_, too? OpenCV does have a destroyAllWindows() method, and you are correct to call it there.
Yes,"cv2.destoryAllWindows()". It won't work, and shows object has no attribute 'destoryAllWindows'. The version of python and opencv i used are 2.7.3 and 2.3.1.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.