简体   繁体   English

Raspberry Pi:使用IF环路检测摄像头,gphoto2

[英]Raspberry Pi: Detect camera with IF loop, gphoto2

I'm trying to find a way to detect if a camera is found for gphoto2, or not. 我正试图找到一种方法来检测是否找到了gphoto2的相机。

I've posted in the gphoto2 forum, but figured I'd try here too. 我已经在gphoto2论坛上发帖了,但我想我也会在这里试试。 One can issue the command, gphoto2 --auto-detect, and it will list cameras that are detected. 可以发出命令gphoto2 --auto-detect,它将列出检测到的摄像机。

I'm running a large python script that at one point, calls gphoto2 to take a picture and download the image. 我正在运行一个大型的python脚本,一次调用gphoto2来拍照并下载图像。 I'm wanting to find a statement that I can put in an IF Loop, to where the take picture and download image command is only issued after entering in the loop if the camera is detected. 我想找一个可以放入IF循环的语句,只有在检测到摄像机后进入循环后才会发出拍照和下载图像命令。

quick google reveals python bindings for gphoto2 http://magiclantern.wikia.com/wiki/Remote_control_with_PTP_and_Python . 快速谷歌揭示了gphoto2的python绑定http://magiclantern.wikia.com/wiki/Remote_control_with_PTP_and_Python

Other variant is to call a console command ie 其他变体是调用控制台命令即

from subprocess import call
call(["gphoto2", "--auto-detect"])

It is up to you how long you will wait for camera to be detectend before you give up. 在你放弃之前,你需要多长时间等待相机被发现。

If you are going with loop, remember to put some sleep command in. 如果你要使用循环,请记住放入一些睡眠命令。

timeout = time.time() + 60
detected = False
while time.time() < timeout:
    if is_device_available():
        detected = True
        break
    # maybe show some feedback why he has to wait
    time.sleep(1)
if not detected:
    raise Exception('Camera device not detected')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM