Ulybin Vitaliy Ulybin Vitaliy - 3 months ago 52
Linux Question

Saving a Video in OpenCV (Linux, Python)

There is an example that works on Windows (original):

import numpy as np
import cv2

cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XDIV')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
out.write(frame)
cv2.imshow('frame',gray)
if cv2.waitKey(0) & 0xFF == ord('q'):
break

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


In Linux program provides:


AttributeError: 'module' object has no attribute 'VideoWriter_fourcc'


Help make it work in Linux.

Answer

I didn't try but this should work :

fourcc = cv2.cv.CV_FOURCC(*'XVID')