【问题标题】:can't capture image by raspberry pi camera in python无法通过python中的树莓派相机捕获图像
【发布时间】:2017-07-13 15:30:26
【问题描述】:

我在尝试使用 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

暂时解决了问题,但重启树莓派后又出现了。

请帮我解决这个问题。

【问题讨论】:

    标签: python python-3.x camera raspberry-pi raspbian


    【解决方案1】:

    编辑文件/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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 1970-01-01
      • 2023-03-11
      • 2023-03-30
      相关资源
      最近更新 更多