下面的代码应该捕获并保存视频。
import cv2
import numpy as np
from skimage.filters import gaussian
capture = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('My video.avi', fourcc, 10, (640,480))
while capture.isOpened:
ret, frame = capture.read()
if ret==True:
frame = gaussian(frame, sigma=5, multichannel=True)
out.write(frame)
cv2.imshow('My video', frame)
if cv2.waitKey(1) == 27:
break
capture.release()
out.release()
cv2.destroyAllWindows()
但是,出现以下错误:
error: OpenCV(3.4.3) D:\Build\OpenCV\opencv-3.4.3\modules\videoio\src\cap_ffmpeg.cpp:296: error: (-215:Assertion failed) image.depth() == CV_8U in function 'cv::`anonymous-namespace'::CvVideoWriter_FFMPEG_proxy::write'
如果我删除了高斯模糊,则该代码有效。怎么了?