我已經看過OpenCV的Python example關於如何使用VideoCapture
和VideoWriter
來捕獲和寫出視頻文件。但我不斷收到:如何使用OpenCV和Python錄製視頻?
OpenCV Error: Assertion failed (dst.data == dst0.data) in cvCvtColor, file
/tmp/opencv-n8PM/opencv-2.4.7.1/modules/imgproc/src/color.cpp, line 4422
Traceback (most recent call last):
File "examples/observer/observer.py", line 17, in <module>
video_writer.write(frame)
cv2.error: /tmp/opencv-n8PM/opencv-2.4.7.1/modules/imgproc/src/color.cpp:4422: error:
(-215) dst.data == dst0.data in function cvCvtColor
清理照相機。
下面是代碼:
#!/usr/bin/env python import cv2
if __name__ == "__main__":
# find the webcam
capture = cv2.VideoCapture(0)
# video recorder
fourcc = cv2.cv.CV_FOURCC(*'XVID') # cv2.VideoWriter_fourcc() does not exist
video_writer = cv2.VideoWriter("output.avi", fourcc, 20, (680, 480))
# record video
while (capture.isOpened()):
ret, frame = capture.read()
if ret:
video_writer.write(frame)
cv2.imshow('Video Stream', frame)
else:
break
capture.release()
video_writer.release()
cv2.destroyAllWindows()
它工作嗎?您可能會接受一個答案,或編輯您的解決方案。 –