Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Saving video from webam stream - no file created

I have followed the tutorial from this site about saving video streams to a file: Link to tutorial

The code starts streaming from the webcam, but when I press 'Esc' no avi-file is created

My code:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

#fourcc = cv2.VideoWriter_fourcc(*'XVID') <-- this line results in an error 
fourcc = cv2.cv.CV_FOURCC('X','V','I','D')

out = cv2.VideoWriter('home/pi/video/output.avi',fourcc, 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(1) & 0xFF == ord('q'):
            break
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

I am using python 2.7 and OpenCV-2.4.10 on my raspberry Pi.

Also, I have tried to use 2 or 3 different codes on blogs used for the same purspose, and none of them saves a video file, eventhough the rest of the code works well.

Do I need to install some packages,or how can I solve this issue?

Best regards

Saving video from webam stream - no file created

I have followed the tutorial from this site about saving video streams to a file: Link to tutorial

The code starts streaming from the webcam, but when I press 'Esc' no avi-file is created

My code:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

#fourcc = cv2.VideoWriter_fourcc(*'XVID') <-- this line results in an error 
fourcc = cv2.cv.CV_FOURCC('X','V','I','D')

out = cv2.VideoWriter('home/pi/video/output.avi',fourcc, 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(1) & 0xFF cv2.waitKey(10) == ord('q'):
27:
            break
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

I am using python 2.7 and OpenCV-2.4.10 on my raspberry Pi.

Also, I have tried to use 2 or 3 different codes on blogs used for the same purspose, and none of them saves a video file, eventhough the rest of the code works well.

Do I need to install some packages,or how can I solve this issue?

Best regards

Saving video from webam stream - no file created

I have followed the tutorial from this site about saving video streams to a file: Link to tutorial

The code starts streaming from the webcam, but when I press 'Esc' no avi-file is created

My code:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

#fourcc = cv2.VideoWriter_fourcc(*'XVID') <-- this line results in an error 
fourcc = cv2.cv.CV_FOURCC('X','V','I','D')

out = cv2.VideoWriter('home/pi/video/output.avi',fourcc, cv2.VideoWriter('/home/pi/video/output.avi',fourcc, 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
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

I am using python 2.7 and OpenCV-2.4.10 on my raspberry Pi.

Also, I have tried to use 2 or 3 different codes on blogs used for the same purspose, and none of them saves a video file, eventhough the rest of the code works well.

Do I need to install some packages,or how can I solve this issue?

Best regards

edit: added / to the file-path.