Opencv Raspberry Python3 [英] Opencv Raspberry python3
问题描述
我想将Opencv3与raspberryPi一起使用,但是当我打开相机并对其进行测试时,没错,
I want to use Opencv3 with my raspberryPi, but when I open the camera, and I test it, it's right that, don't work
import cv2
cap = cv2.VideoCapture(0)
while 1:
if cap.isOpened():
print("Work")
else:
print("Don't work)
推荐答案
通常,如果要在Raspberry Pi上使用相机,则应该执行以下操作:
In general, if you want to use the camera on a Raspberry Pi, you should probably do the following:
步骤1-在raspi-config中启用摄像头
从raspi-config
开始:
sudo raspi-config
并找到启用摄像头的命令-每个版本都不相同.启用相机并允许重新启动.
and find the command to enable the camera - it differs from version to version. Enable the camera and allow the reboot.
第2步-更新Raspberry Pi固件
通常,最好确保固件为最新版本,以便最新,最强大的内核和驱动程序正常工作.
It's generally a good idea to ensure that the firmware is up-to-date so the latest, greatest kernel and drivers work.
sudo rpi-update
此后需要重新启动.
步骤3-检查相机是否可以拍摄静止图像
您可以使用raspistill
进行检查,以进行如下拍照:
You can check this with raspistill
to take a photo as follows:
raspistill -o picture.jpg
第4步-配置v4l2
如果您还想使用 OpenCV 并拍摄视频,则需要确保已安装v4l2
"Linux视频" 模块.您可以执行以下操作:
If you additionally want to use OpenCV and shoot video, you will need to ensure that the v4l2
"Video for Linux" module is installed. You can do that with:
sudo modprobe bcm2835-v4l2
如果正确加载,则您应该能够从OpenCV中的摄像机访问视频.您可以在/etc/modules
的底部添加一行,而不是在每次引导后都重复该命令,就像这样:
If that loads correctly, your should be able to access video from the camera in OpenCV. Rather than repeating the command after every boot, you can add a single line to the bottom of /etc/modules
so it looks like this:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# SETCHELL v4l2 added for OpenCV video capture
bcm2835-v4l2
我通常将我的姓氏放在我编辑的任何系统文件中,然后如果我弄乱了,我可以很容易地找到与之相关的任何文件,也可以备份它们,还可以告诉任何我在StackOverflow上提供帮助的人我所做的任何系统更改-是的,我有点强迫症!
I generally put my surname in any system files I edit then I can easily find any files I have dinked around with if I make a mess, and I can also back them up, and also tell anyone I help out on StackOverflow of any system changes I have made - yes, I am a bit OCD!
如果仍然无法正常工作,请检查电缆是否正确-银色连接器必须朝向HDMI端口.
If it still doesn't work, check your cable is correct - the silver connector must face the HDMI port.
关键字:Raspberry Pi,raspi,RPi,相机,相机电缆,静止图像,照片,视频,OpenCV,v4l,v4l2,Linux视频,raspi-config,raspistill,rpi-update, bcm2835,bcm2835-v4l2,模块,modprobe
Keywords: Raspberry Pi, raspi, RPi, camera, camera cable, still, photo, video, OpenCV, v4l, v4l2, Video for Linux, raspi-config, raspistill, rpi-update, bcm2835, bcm2835-v4l2, modules, modprobe
这篇关于Opencv Raspberry Python3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!