我正在尝试找到一种方法来检测是否找到了用于gphoto2的摄像头。
我已经在gphoto2论坛上发表了帖子,但我想我也应该在这里尝试一下。用户可以发出命令gphoto2 --auto-detect,它将列出检测到的摄像机。
我正在运行一个大型python脚本,该脚本调用gphoto2来拍摄照片并下载图像。我想找到一个语句,我可以把它放在一个IF循环中,在这个循环中,只有在检测到摄像头的情况下,才会在进入循环后发出拍摄照片和下载图像命令。
发布于 2013-03-26 02:08:53
快速google揭示了gphoto2 http://magiclantern.wikia.com/wiki/Remote_control_with_PTP_and_Python的python绑定。
另一个变体是调用控制台命令,即
from subprocess import call
call(["gphoto2", "--auto-detect"])在你放弃之前,你要等多久才能检测到摄像头,这取决于你自己。
如果你要使用循环,记得放入一些睡眠命令。
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')https://stackoverflow.com/questions/15621339
复制相似问题