One of the most enjoyable Open Source software discoveries I have found recently is the tool gPhoto2 for remote control of DSLR cameras, or as it is commonly called in Anglo-Saxon terms “Tethered” from Unix-based systems, that is, Linux or Mac.
gPhoto was released in its stable version at the end of 2015, although it has been in development since 2011, and it is based on the PTP or Picture Transfer Protocol, proposed in 2008 as a standard under the designation “ISO 15740:2008 Photography — Electronic still picture imaging — Picture transfer protocol (PTP) for digital still photography devices”.
PTP is a protocol adopted by the main camera manufacturers, in order to allow remote control and image transfer. gPhoto with its libgphoto2 library is the most consistent option for remote control of DSLR cameras, without having to resort to commercial tools or the SDKs of each manufacturer.
So far I have only used this tool from MacOsX, which is very easy to install from Ports, with a simple:
sudo port install gphoto2
Or on Linux
sudo apt-get install gphoto2
On Mac OsX it is very likely that there is some application that captures the connection with your camera once connected, so it is recommended, before starting to work with gPhoto, to do a:
killall PTPCamera
One of the first commands we can run to test our connection is:
Launch the list of connected cameras and port:
gphoto2 --auto-detect
Or to dump all the camera information (model, serial number, storage, etc…):
gphoto2 --summary
But perhaps the most interesting command to know the capabilities and particular status of each camera function is:
gphoto2 --auto-detect --list-config
This dumps
/main/capturesettings/minimumshutterspeed /main/capturesettings/isoautohilimit /main/capturesettings/dlighting /main/capturesettings/highisonr /main/capturesettings/imagequality /main/capturesettings/shootingspeed /main/capturesettings/moviequality /main/capturesettings/flashshutterspeed /main/capturesettings/longexpnr /main/capturesettings/assistlight /main/capturesettings/exposurecompensation /main/capturesettings/exposurecompensation2 /main/capturesettings/flashmode .... etc
If we do, for example, a:
gphoto2 --get-config /main/capturesettings/f-number
We obtain the list of available aperture openings, either by index “f-number” or by value “f-number2”.
Choice: 0 f/1.8 Choice: 1 f/2 Choice: 2 f/2.2 Choice: 3 f/2.5
If next, we want to set the aperture, we will do a:
gphoto2 --set-config-index /main/capturesettings/f-number=2
gphoto2 --set-config-index /main/capturesettings/f-number2=f/2.8
Similarly, if we want to know the available shutter speeds and set it on the camera, we will do a:
gphoto2 --get-config /main/capturesettings/shutterspeed2
gphoto2 --set-config-index /main/capturesettings/shutterspeed2=1/125
To know and adjust the sensitivity (we can only enter the index, not the value):
gphoto2 --get-config /main/imgsettings/iso
gphoto2 --set-config-index /main/imgsettings/iso=8
And finally to shoot:
If we want to shoot and download, setting the file name:
gphoto2 --capture-image-and-download --filename JP_%H%M%S.%C
And if we want to store it on the camera’s card:
gphoto2 --set-config capturetarget=1
gphoto2 --capture-image
Although it may seem a bit confusing, it is easy to program a bash script that helps us set the exposure and shoot:
#!/bin/bash killall PTPCamera #gphoto2 --set-config-index /main/imgsettings/iso=8 gphoto2 --set-config-value /main/capturesettings/f-number=f/$1 gphoto2 --set-config-value /main/capturesettings/shutterspeed2=$2 #gphoto2 --capture-image-and-download --filename JP_%H%M%S.%C #gphoto2 --set-config capturetarget=1 gphoto2 --capture-image
In this way, simply by entering the first parameter as the aperture and the second as the speed, we can already set exposure and shoot the camera.
If, for example, we want to trigger autofocus to set the focus, we do a:
gphoto2 --set-config autofocusdrive=1
Another case that may interest us is to take a preview image, for which we can do:
gphoto2 --capture-preview --set-config viewfinder=0
Another possibility is to shoot the camera from its own shutter and download the image to an external drive:
gphoto2 --capture-tethered --filename="/images/image-%Y%m%d-%H%M%S.%C"
And of course we can access and download the images from our camera:
gphoto2 --list-files
gphoto2 --get-file 1
