自动检测Raspberry-Pi相机

时间:2015-02-04 16:53:48

标签: python raspberry-pi

我有一个问题,有没有办法检测Raspi相机 HW 模块?我正在用Python编写一个项目,我需要验证Camera硬件模块是否连接到RPi,因为我需要将相同的Python项目复制到几个RP,但是其中一些不会连接相机。我正在使用Picamera SW模块,但是如果摄像机存在于 / dev 树中的某个位置,那么我正在考虑导入这样的模块,如果可能或者实现此目的,现在是否有人?

提前致谢

2 个答案:

答案 0 :(得分:0)

好的,这是我在google搜索后找到的解决方案是命令 vcgencmd ,用于检测相机是否已连接,所以通过发出Python来执行子进程我是设法得到了预期的结果

O.S.命令“vcgencmd get_camera”给出了输出:

supported=0 detected=0

所以通过使用子进程python调用:

import subprocess
c = subprocess.check_output(["vcgencmd","get_camera"])
int(camdet.strip()[-1]) #-- Removes the final CR character and gets only the "0" or "1" from detected status

if (c):
    print "Camera detected"
else:
    print "not detected"

希望这对其他人有用,欢迎任何更简单的消化解决方案

答案 1 :(得分:0)

我用它来检查picamera是否可用,基于上一篇文章。 如果您获得支持并且检测到值为1,则您可以使用picamera

#!/usr/bin/python
import subprocess
#--next line returns something like supported=1 detected=1
#--if get supported and deteted valued at 1 you have a picamera available    
commandResult = subprocess.check_output("vcgencmd get_camera", shell=True)
相关问题