The joy of libgphoto2

Whilst I was on holiday I took a bit of a leap into the unknown and decided I’d try to implement support for DSLRs in the camera library I’ve written for oacapture and related applications, the intent being to use libgphoto2 to control the cameras (and libraw to manipulate the images).

libgphoto2 looks like a very impressive piece of software, supporting a huge number of DSLRs, but the documentation is, well, shall we say “somewhat lacking in depth”? There are a few sample programs that aren’t entirely convincing, and some function-level documentation generated by doxygen that doesn’t really tell you everything you need to know.

I’ve yet to work out what’s going on with the non-PTP2 cameras so I’ve decided to ignore those for the moment and just concentrate on the ones that do support PTP2. At this point I have my code recognising that my Canon 450D is connected and reading its model name to return to the caller. That’s about as far as I’ve got.

Much of the camera interface appears to centre around the concept of “widgets”. If you’re writing a GUI application (as I am) this may be a little confusing given that “widget” is also a term used for an object that appears a in GUI, but in this case the widgets appear to be nodes in a tree of information that describes the camera and its features, arranged in a similar way to a filesystem, in that each node has a “name” that is formed by concatenating the names of all the widgets from the “root” node with the components being separated by the slash (“/”) character. So /main/imgsettings/iso, for example. The leaf nodes represent actual information about the camera and contain data such as whether the data is read only, what type of information it is and what values it can take (if appropriate).

And this is where the fun starts… There doesn’t appear to be any meaningful documentation of what those “name” values can be, nor what they mean in terms of operating the camera. Some, such as /main/imgsettings/iso might be reasonably obvious, but others aren’t so obvious. For example, how does /main/imgsettings/autoiso differ from /main/imgsettings/isoauto, especially if both exist for the same camera?

I have discovered that leaf nodes also have a “label”. The label value appears to be a bit more camera-dependent, but may sometimes help with determining what any given leaf node refers to because it turns out that supported PTP2 cameras have a text file that describes their functions (in camlibs/ptp2/cameras in the source for the library though I’ve no idea if those are pulled into the installed binaries. In these files it appears to be the label that is used to configure what actually happens in terms of the PTP2 protocol, so searching the file for a given camera for the name of a leaf node and then for the associated label may help to work out what it actually does.

There doesn’t appear to be any definitive documentation on all possible values for the “name” fields and it may be that different names actually do the same thing (I can’t be sure at the moment), so writing code that handles all possible options doesn’t appear possible. At the moment I have created a list of 156 different names that are used in the configuration files mentioned above. Perhaps the next step is to pair those with labels and see what makes sense to code up in a first pass.

I’ll post on further progress when I make it.

This entry was posted in Astronomy, Computing and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *