如何让 cv2.VideoCapture(0) 识别树莓派的 USB 摄像头。
def OnRecord(self, evt):
capture = cv2.VideoCapture(0)
if (not capture.isOpened()):
print "Error"
# video recorder
fourcc = cv2.cv.CV_FOURCC(*'XVID') # cv2.VideoWriter_fourcc() does not exist
video_writer = cv2.VideoWriter.open("output.mp4", fourcc, 20, (640, 480), True)
# record video
while (capture.isOpened()):
ret, frame = capture.read()
if ret==True:
video_writer.write(frame)
cv2.imshow('Video', frame)
else:
break
def OnCancel(self, evt):
capture.release()
video_writer.release()
cv2.destroyAllWindows()
但它只打印错误。
所以我想捕获没有打开。可能是什么原因?
我从 opencv 文档中尝试了这段代码,但对我没有用。
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
任何帮助将不胜感激。
最佳答案
为 linux 驱动程序加载正确的视频。
sudo modprobe bcm2835-v4l2
关于python - cv2.videocapture 不适用于 Raspberry-pi,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38302161/