在python中无法通过树莓派相机捕捉图像
尝试使用Raspberry Pi相机拍摄图像时出现问题。
当我执行此代码时:
import sys
sys.path.append('/usr/local/lib/python3.4/site-packages')
import cv2
import numpy as np
import detect
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
img = detect.detect(frame)
cv2.imshow('frame',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
我收到错误:
Traceback (most recent call last):
...
...
...
TypeError: 'NoneType' object is not subscriptable
我搜索解决这个问题,并找到一个命令进入终端:
sudo modprobe bcm2835-v4l2
它暂时解决了问题,但是在重新启动Raspberry Pi之后再次出现。
请帮我解决这个问题。
编辑文件/etc/modules
(以root身份)并添加bcm2835-vl42
行,如下所示:
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# v4l2 added for OpenCV video capture
bcm2835-v4l2
链接地址: http://www.djcxy.com/p/77159.html