有一个适用于 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()
在Linux程序中提供:
AttributeError: 'module' object has no attribute 'VideoWriter_fourcc'
帮助它在 Linux 中运行。
最佳答案
我没试过,但这应该行得通:
fourcc = cv2.cv.CV_FOURCC(*'XVID')
关于python - 在 OpenCV 中保存视频(Linux、Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39119893/