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

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

问题描述

我尝试使此代码与树莓派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

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

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