ami*_*bag 1 python opencv raspberry-pi
我尝试使此代码与树莓派摄像头一起使用。如何让 cv2.VideoCapture(0) 将树莓派摄像头识别为指定摄像头
import cv2
def diffImg(t0, t1, t2):
d1 = cv2.absdiff(t2, t1)
d2 = cv2.absdiff(t1, t0)
return cv2.bitwise_and(d1, d2)
cam = cv2.VideoCapture(0)
winName = "Movement Indicator"
cv2.namedWindow(winName, cv2.CV_WINDOW_AUTOSIZE)
t_minus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
t = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
t_plus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
while True:
cv2.imshow( winName, diffImg(t_minus, t, t_plus) )
# Read next image
t_minus = t
t = t_plus
t_plus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
key = cv2.waitKey(10)
if key == 27:
cv2.destroyWindow(winName)
break
print ("Goodbye")
Run Code Online (Sandbox Code Playgroud)
您不能用于cv2.VideoCapture()
RaspiCam。
仅cv2.VideoCapture()
适用于 USB 摄像头,不适用于 CSI 摄像头。
如果你想使用RaspiCam进行抓图,可以参考这个 教程
更新:答案不再正确,因为现在您可以使用cv2.VideoCapture()
下面提到的评论。
归档时间: |
|
查看次数: |
26062 次 |
最近记录: |