According to a tutorial this code helps me to capture video, also pass it in gray scale.
However, when I run it, the video display comes out in black and also the video that is saved has almost no weight (4kb).
Could someone give me a hand?
info sistema: Python 2.7 en IDE spyder. 64bits
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 21 13:22:58 2017
@author:
"""
import cv2
import numpy as np
cap=cv2.VideoCapture(0);
fourcc = cv2.VideoWriter_fourcc(*'XVID')
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',frame)
try:
out.write(frame)
except:
print ('ERROR - Not writting to file')
cv2.imshow('gray',gray)
if cv2.waitKey(0):
break
cap.release()
out.release()
cv2.destroyAllWindows()
del(cap)