gpt4 book ai didi

python - 在 OpenCV 中保存视频(Linux、Python)

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:41:37 26 4
gpt4 key购买 nike

有一个适用于 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com