覆盆子pi和OpenCV的问题

时间:2016-02-05 12:51:29

标签: python opencv raspberry-pi

我有一个覆盆子pi的项目,我正在使用python。但是,当我尝试运行此代码时,OpenCV出现问题:

`import numpy as np
 import cv2

 cap = cv2.VideoCapture(0)

 while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()`

我收到此错误:

  

OpenCV错误:断言失败(scn == 3 || scn == 4)在cvtColor中,文件/home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp,第8000行

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp:8000:  error: (-215) scn == 3 || scn == 4 in function cvtColor"

我有Python 3.4.2,OpenCV 3.1.0和Numpy 1.8.2。

1 个答案:

答案 0 :(得分:2)

所以我找到了答案。我所要做的就是在我的树莓派上运行这段代码:

sudo modprobe bcm2835-v4l2

感谢您的帮助。