This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Graphics & Multimedia

Controlling your camera from your computer with gPhoto

By Nathan Willis on June 06, 2008 (4:00:00 PM)

Share    Print    Comments   

Both of the big powerhouses in the digital SLR camera market -- Canon and Nikon -- make software with which you can control your camera from your PC through an attached USB cable. It is a nice tool for situations when manually triggering the shutter might cause shake (such as long exposures), or for automating multiple shots at timed intervals. But, naturally, the camera makers don't supply this software for free operating systems -- and just as naturally, the open source world has an answer. You can perform the same remote operation functions using gPhoto.

The gPhoto project is one of those open source gems that works so well that it is easy to forget it is there. Plug in a digital camera, and the photo management app of your choice -- be it F-Spot, digikam, gtkam, or another -- identifies the camera, then quietly and expertly retrieves your photos with little to no fuss. But for most cameras, gPhoto can do considerably more, including just about any function supported by the camera's firmware. That includes USB image capture, a function normally thought of in the context of always-attached webcams, but available for nicer digital cameras, too.

To take advantage of this feature, you must have a supported camera and (in some cases) a sufficiently recent build of gPhoto. While the basic photo upload/download capabilities of gPhoto cover close to 1,000 different camera models, not all cameras support USB camera control, and not all that do have been figured out by the gPhoto team. Check the camera control page of the project's wiki to see if yours is on the list.

I use two cameras, a Canon S2 IS point-and-shoot, and a Canon EOS 5D SLR. Both are on the remote control supported list, although a note by the 5D indicates that gPhoto version 2.4.0 or newer is required. Since gPhoto is a standard component of most desktop Linux systems, you should be able to find an official package through your distribution; for historical reasons, the package name is gphoto2, not gphoto.

Getting started

Once I had installed a suitably recent version of gphoto2, I attached my 5D to the computer via its USB cable and switched it on. As usual, a message box popped up alerting me that a camera had been detected and asking whether I wanted to download new photos to the PC or do nothing. Plugging in your own camera might not result in such a dialog box if you have previously told your system to automatically begin extracting photos. If you cannot interrupt the photo extraction process, just wait for it to finish.

The gphoto2 package includes a command-line and ncurses-capable client program called gphoto2. You can use it to download images from the camera's memory card if you wish, but it is also useful for querying the camera and exploring its extra features. Typing gphoto2 -a at a bash prompt will return the a list of the camera's supported functions. For our purposes, this includes capture-image and capture-preview. The 5D does not record video or sound; cameras that do may also be capable of capture-movie and capture-sound.

At this point, gphoto2 might report that your camera is incapable of certain features (such as capture-image) that the gPhoto Web site says are supported. If that happens, the culprit is likely to be the connection mode. Some cameras (especially point-and-shoot models) can connect over USB only in Picture Transport Protocol (PTP) mode. Spiffier models may have additional modes, and depending on the model, using gphoto2 to access the advanced functions might require switching the camera into one of them.

The 5D has two options, PTP mode and "PC Connection" mode; the latter is required for remote control with gphoto2. On the 5D, at least, you can change the mode only through the camera's built-in menus and controls via the LCD screen. Once the camera was set in PC Connection mode, gphoto2 reported capture-image and capture-preview as available functions.

Taking basic pictures

The capture-image command itself fires the shutter, just as if you'd pressed the onboard shutter release or a wired or wireless remote trigger. That means it uses the camera's picture-taking settings -- shutter speed, aperture, autofocus, resolution, and so on -- as is. You must set up the shot beforehand; all gphoto2 does is send the signal to fire. Capture-image stores the resulting photo to the camera's memory or memory card, just as with a manual shot. The only advantage you gain is the convenience of triggering the shot from the PC.

You can spice things up by adding arguments to the capture-image command. The -I or --interval argument allows you to specify an time interval, after which the camera will take additional shots. If you use -I, you should consider adding -F or --frames to specify how many shots to take in this manner. If you omit -F, gphoto2 will continue taking pictures at the specified interval until the available storage space on the camera is filled.

Some gphoto2 users have reported a bug with the capture-image command, in which the gphoto2 command does not terminate after the picture is taken. The good news is that gphoto2 has been fixed, so if your distro does not have an update yet, you can grab the source code and build it yourself if you're hit with this bug. Otherwise, if you are at the keyboard when the problem arises, you can safely terminate gphoto2 with Ctrl-C.

In contrast to capture-image, the capture-preview command snaps a picture and downloads the result directly to the attached PC, bypassing the camera's storage altogether. Taking advantage of this distinction allows you to snap a continuous stream of timed interval photos when combined with the -F and -I arguments, regardless of the amount of space available on the camera.

Going further

A vanilla --capture-image command fires a shot without making any adjustments. For many camera models, you can change the aperture, shutter speed, ISO settings, and other parameters with a --set-config argument. To find out which parameters gphoto2 can change on your particular camera, type gphoto2 --list-config. You can query each individual setting with gphoto2 --get-config attribute. The program will return the current value and a list of all available values, which is especially helpful for things like aperture where sophisticated cameras (or attached lenses) can have several dozen possible values that you might not have memorized. You change the setting with gphoto2 --set-config attribute value.

If all that command-line typing starts to get old, you can launch an interactive, menu-driven interface into the same settings with gphoto2 --config. This interface is text only -- using ncurses -- but it is more convenient than typing individual get/set commands if you have a lot of values to change.

The --hook-script option offers lots of possibilities. By adding --hook-script=/path/to/some/script.sh to the end of your --capture-image command, you tell gphoto2 to execute a shell script after the command completes. This could do anything -- from rsyncing the image directory to sending you an email message.

Speaking of scripting, the command-line image capture abilities of gphoto2 are ripe for automation. Snapping a frame or two while you are at a computer that's physically tethered to the camera has its uses. Of course you can take longer shots with reduced vibration, you can hide yourself a few feet away and snap up-close pictures of easily frightened birds, and so on. But triggering gphoto2 to capture photos based on external events -- hardware- or software-driven -- without your presence is a lot more interesting.

That said, I have yet to see anyone making serious real-world use of gphoto2's scriptability in the area of remote camera control. If you know of a good example, and especially if you have firsthand experience with it, please share the details in a comment. In the meantime, find a long USB cable and start shooting.

Share    Print    Comments   

Comments

on Controlling your camera from your computer with gPhoto

Note: Comments are owned by the poster. We are not responsible for their content.

Finally I can have some scripting with my camera

Posted by: Danilo Câmara on June 06, 2008 05:16 PM
That's good news. Already checked it worked with a Nikon DSLR in my Desktop. Can't wait to have some fun with the camera attached to a portable Nokia N810.
[Modified by: Danilo Câmara on June 06, 2008 01:19 PM]

#

Controlling your camera from your computer with gPhoto

Posted by: Anonymous [ip: 12.169.163.241] on June 06, 2008 05:40 PM
Thanks Nathan, this is a great article, and hurrah for the folks who maintain gphoto. This remote control stuff is a premium feature in some Canon cameras, which is an artificial distinction since it's all done in software. Now us peons can have it too, mwahahaaa!

#

Controlling your camera from your computer with gPhoto

Posted by: Anonymous [ip: 82.250.109.254] on June 06, 2008 11:26 PM
Wow, this literally screams for inclusion in Cheese, the new Gnome photo booth... Snapping pictures at a party might be fun with a 320x200 webcam, but framing the event in all its DSLR glory would be priceless

#

Controlling your camera from your computer with gPhoto

Posted by: Anonymous [ip: 24.5.175.47] on June 07, 2008 07:13 PM
The Canon 5D driver was added to gphoto by Paul Walmsley for the Internet Archive.

The Internet Archive digitizes books using the Canon 5D and 1Ds, and takes more than 8 million pictures every month using gphoto!

#

Re: Controlling your camera from your computer with gPhoto

Posted by: Anonymous [ip: 128.220.159.75] on June 09, 2008 07:48 PM
I might add that the Internet Archive does indeed make use of gPhoto's scripting by way of their Scribe2 software: https://launchpad.net/scribe2

#

Controlling your camera from your computer with gPhoto

Posted by: Anonymous [ip: 76.221.141.5] on June 09, 2008 03:29 AM
Hello. What I'd really like to do is have a notebook computer mounted to a tripod, connected to a camera (EOS 20d), so that when I take photos, they are automatically displayed across all 14 inches of my notebook's screen. My camera has a 1.8" post-view screen, but it's too small to tell if the photo is focused where I want, or if someone has a nasty facial expression as opposed to a graceful smile.

-Dave

#

Re: Controlling your camera from your computer with gPhoto

Posted by: Anonymous [ip: 216.252.84.84] on June 09, 2008 06:03 PM
Having the pictures displayed on the screen is trivial enough since we're speaking of automation through scripts. Just launch whatever lightweight image displayer for x seconds and you're all set. Mounting the laptop on a tripod is an entirely different problem because they're not designed for that. Just put it on a chair with a pile of big books, just like people without tripods do to take pictures of themselves. :)

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya