Ask Your Question
0

opencv picture size 0x0 is invalid

asked 2017-11-01 17:52:30 -0500

Rock gravatar image

I try to take video stream (live stream) from a cam with rtsp protocol, saying that on windows works perfectly but linux does not want to leave, the code is as follows:

 import cv2

if __name__ == "__main__":
    # find the webcam
    capture = cv2.VideoCapture(0)
   frame_width = int(capture.get(3))
   frame_height = int(capture.get(4))
    # video recorder
    fourcc = cv2.cv.CV_FOURCC(*'XVID')  # cv2.VideoWriter_fourcc() does not exist
    videoOut = cv2.VideoWriter("output.avi", fourcc, 20.0, (frame_width, frame_height))

    # record video
    while (capture.isOpened()):
        ret, frame = capture.read()
        if ret:
            videoOut.write(frame)
            cv2.imshow('Video Stream', frame)

        else:
            break

        # Tiny Pause
        key = cv2.waitKey(1)

    capture.release()
    videoOut.release()
    cv2.destroyAllWindows()

return this error: picture size 0x0 is invalid

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-11-01 22:15:05 -0500

supra56 gravatar image
import cv2

cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object
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

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-11-01 17:52:30 -0500

Seen: 380 times

Last updated: Nov 01 '17