我正在尝试使 raspberry pi 相机与 opencv 一起使用 [英] I am trying make the raspberry pi camera work with opencv

查看:24
本文介绍了我正在尝试使 raspberry pi 相机与 opencv 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使此代码与 raspberry pi cam 一起使用.你如何让 cv2.VideoCapture(0) 将树莓派摄像头识别为指定摄像头

I tried making this code work with the raspberry pi cam. how do you make the cv2.VideoCapture(0) recognise the raspberry pi camera as the designated camera

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")

推荐答案

您不能将 cv2.VideoCapture() 用于 RaspiCam.

You cannot use cv2.VideoCapture() for RaspiCam.

cv2.VideoCapture() 仅适用于 USB 摄像头,不适用于 CSI 摄像头.

The cv2.VideoCapture() is only for USB camera, not for CSI camera.

如果你想用RaspiCam进行抓拍,可以参考这个教程

If you want to use RaspiCam for capturing, you can refer this tutorial

更新:答案不再正确,因为现在您可以使用 cv2.VideoCapture() 作为下面提到的评论.

Update: The answer is no longer correct since now you can use cv2.VideoCapture() as the comment mentioned bellow.

这篇关于我正在尝试使 raspberry pi 相机与 opencv 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆