gun*_*ner 5 python raspberry-pi
我跟着这个网站(https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/)来设置我的picamera,但我有一个问题使用 picamera 模块。我确实安装了 picamera 模块,这张图片来自 pip freeze。
你可以看到我已经有 picamera 1.13,但是当我尝试 test_image.py 时,它说“没有名为‘picamera’的模块”。
我已经卸载并安装了很多次,但错误仍然存在。我该如何解决?
test_image.py
# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
rawCapture = PiRGBArray(camera)
# allow the camera to warmup
time.sleep(0.1)
# grab an image from the camera
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
# display the image on screen and wait for a keypress
cv2.imshow("Image", image)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
对于 python3,您必须尝试下面的命令。请记住,您需要在主目录中打开终端。
sudo -H apt install python3-picamera
sudo -H pip3 install --upgrade picamera[array]
Run Code Online (Sandbox Code Playgroud)
让我知道它是否有效!
小智 2
当您运行命令pip3 install picamera时,它将显示已满足要求,后跟一个路径(前提是您已经安装了 picamera)。现在复制该路径并将其包含在您的程序中,如下所示:
import sys
sys.path.append('paste the copied path here')
from picamera.array import PiRGBArray
from picamera import PiCamera
Run Code Online (Sandbox Code Playgroud)