简体   繁体   中英

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.

I've posted in the gphoto2 forum, but figured I'd try here too. One can issue the command, gphoto2 --auto-detect, and it will list cameras that are detected.

I'm running a large python script that at one point, calls gphoto2 to take a picture and download the image. 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.

quick google reveals python bindings for gphoto2 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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