Ask Your Question

Revision history [back]

capture not remaining open

I'm going through the tutorial code to get a good grip on the opencv functionality. I've run into a bit of an issue with my capture apparently not wanting to remain open. The code I'm using has been lifted from the tutorial pages at: link:http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html#exercises.

I get a single frame showing up in the output video, but as far as I can tell the code should just continue to capture.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)

        # write the flipped frame
        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break
cap.release()
out.release()
cv2.destroyAllWindows()

Ideas or hints about possible solutions would be appreciated. Running Ubuntu 16.xx.