【发布时间】:2018-05-23 14:31:59
【问题描述】:
我想用 Raspberry Pi + weedcam (logitech) 录制视频。虽然我发现很多示例实际上几乎与以下代码相同:
import numpy as np
import cv2
path = ('/.../output.avi')
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter(path,fourcc, 20.0, (640,480))
while(cap.isOpened()):
#read the frame
ret, frame = cap.read()
if ret==True:
#Write the frame
video_writer.write(frame)
#show the frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
video_writer.release()
cv2.destroyAllWindows()
第一个问题,我已经尝试了OpenCV write frame to file python的所有解决方案 但似乎这些解决方案不适合我...... 所以我想知道是否有人对此问题有其他解决方案,我将不胜感激! 第二个问题,我发现有人用
cv2.VideoWriter_fourcc('XVID')
而不是
cv2.cv.CV_FOURCC(*'XVID')
这会是问题吗?另外,我尝试使用 cv2.VideoWriter_fourcc('XVID'),但得到一个错误:'module' object has no attribute 'VideoWriter_fourcc'...我该如何解决这个问题? 谢谢!
【问题讨论】:
-
如果这真的是你运行的代码,那么你的变量上限是未定义的。
-
对不起,我忘记复制:cap=cv2.VideoCapture(0),所以我认为问题不在于这一点。
标签: python opencv video webcam