September 17, 2009

Sophisticated Picture Taking With gPhoto

My kids were watching a fancy fashion-model photography show recently on television.  The scene was set on the top of a high-rise building with a cubic-dollar photographer, high-powered flash units, and acrophobic models running around all over the place.  The shoot director barked orders from under a little tent and squinted at a big monitor.

Interesting.  Every time a shot was taken, it magically appeared on the director's monitor.  How do they do that?

A little on-line searching revealed that the technique is called tethered capture and is getting a lot of attention in photography circles.  You need a program that can interact with your camera, both sending commands and reading back settings, in addition to downloading the images.  Nikon and Canon both sell these programs, but they work on Windows machines.  I use Linux for everything.

There is a cool Linux command-line program called gPhoto, that can do tethered capture and a whole lot of other things.  Since it runs on Linux, all kinds of remote control and automation are possible.  I might cover those topics in another article.

It's important to understand the basics of camera/computer image capture first and then move on to tethered mode.

Basic Picture Taking

gPhoto supports a huge variety of cameras and can be downloaded to your Linux machine using your package manager.  Look for gphoto2.  It has a multitude of options from listing information on the camera, to downloading/uploading files, through capturing of images.  There are eight or nine pages of options.  

My equipment represents a typical prosumer setup.  The camera is a Nikon D80 digital SLR, with an 18-200 mm DX autofocus lens.  The laptop is an Asus X83-VM, 2.6 Ghz, duo-core 14" laptop with 4 GB of memory and a 320 GB disk.  The laptop has a 1280 x 800 LED backlit, LCD screen.  I used a 4 foot long A-B USB cable for this article.  I've also used gPhoto successfully on my Asus eeePC Netbook with eeeBuntu and a headless Plug Computer running Ubuntu.

Here is the basic form of the command.

rreilly> gphoto2 [--options]

Capturing an image from the command line is easy.  The first step is to attach the camera to the laptop using the appropriate USB cable.  Next, turn the camera on and point it at your subject.  You should adjust your camera for PTP or computer connection mode.  Mass storage mode (for the USB connection) won't allow any remote camera control.  Take a look at the camera list, to see your camera's capabilities.  Lastly, issue the command to take a picture using the --image option.  The flash may pop up and the shutter will be released.  Focus, aperture, and other settings will need to be set before taking any shots.

rreilly> gphoto2 --image

gPhoto List of ImagesThis will save a new image to the SD card, but it won't download it to the laptop automatically.  With the --image option, you will manually have to issue another set of commands to download the photo from the camera.  Use the -L option to show the files on the camera SD card.  Figure 1 shows a listing of the files on my camera.  Then use the -p option to download your selected file, according to the file number (shown on the left in Figure 1).

rreilly> gphoto2 -L        Lists the files on the SD card.

rreilly> gphoto2 -p 44    Downloads file #44 from the SD card and saves it in the local directory.  The file will be saved, in my example, as DSC_0043.JPG.  

That's the basics of taking a picture and getting from the camera to the laptop.  Next stop, automation.

Capture, Download, and View

Tethered shooting is very popular right now, among professional shooters, for good reason.

Those tiny 2" x 3" screens simply don't give much detail.  Trusting the small screen, even when zooming in to check the detail, may lead you astray, as well.  I've taken plenty of pictures that look fine on the camera, but turn out to be annoyingly slightly out of focus when I finally put the photos on my laptop.
A viable solution, of course, is to view the pictures on a bigger screen.  Viewing the photo on a laptop or larger screen gives immediate feedback on focus, highlights, composition, depth of field, and so on.  The good and bad will jump out at you in a hurry on a bigger screen.  You can make adjustments to the camera settings, to avoid the problems, before your next picture.

Shooting with a cable attached to the camera requires a little bit of finesse and caution.  The connectors are delicate, so be careful.  Some of the pros I've seen, position the laptop on a little stand and then run the USB cable out to the camera.  A good way to try tethered capture is to start using it in the studio.  The laptop can be locked down on something solid and the radius that you will have to pull the cable around can be fairly well controlled.  With experience, other situations to use the camera/laptop combination will present themselves.  Hey, if you start turning out super-fine shots, maybe you'll find yourself up on the top of a building working with gorgeous models some day.

There are a couple of tricks to using tethered mode that aren't very obvious.

First thing is that just using the --capture-tethered won't get the job done.  You also need to use the --hook-script option and call an external program to view the photos.  Here is the command.

rreilly> gphoto2 --capture-tethered --hook-script

You'll find the file in the /usr/share/doc/gphoto2 directory.  Copy the file into your working directory and then make changes with any text editor.

You'll also need to choose a photo viewer program, to see the pictures.  Once a picture is taken the photo will be downloaded into the photo viewer program through the script.  The default script uses the eog (Eye of Gnome) application.  I've used the script with The Gimp and display (the ImageMagick program).  The shell program is pretty simple and you just need to replace the eog entry, under the download section, with your viewer.  Take a look at the file and you'll see how it works.  You might want to check that your viewer of choice is installed and if not, do that.

Once the script is edited to your liking change it's permissions to make it executable.

rreilly>  chmod 777

Type the gphoto command into the terminal, as shown above and hit enter, to execute.

The screen will show the camera initializing and then it will sit there waiting for you to take a shot.  Point the camera at your scene and push the shutter release button.  On occasion, you'll get an error message with no response from the camera.  USB stuff always seems a little touchy, so if this happens just turn the camera off and then back on again.  You can then use the up arrow to recall the command and try again.

Once the picture is taken, it will download immediately and show up in a new window with the viewer program.  Looks pretty darn good, doesn't it?  Maximize the window for the best view.

Now, take another picture.  The picture will download, but this time, gPhoto will ask you if you want to overwrite the file.  Answer "y" and a new window will pop up with your latest photo.  If you answer "n", it will ask you if you want to rename the file.  Answer "y" and then give it a name.  A new viewer window will pop up with the new photo.

Depending on your laptop, you could conceivably have quite a few viewer windows up at one time.  Since I just want to check my work, closing down each window after review, works for me.

If everything is set up to use default settings, the camera will save a copy of each photo on the SD card.

gPhoto and flphotoHaving the individual windows open gives the added benefit of instant photo editing, depending on your viewer.  If you are using The Gimp, you can make a lot of changes to the picture.  Most of the viewers will also let you save the photo, locally on your disk, using a name of your choosing.  I have trouble remembering that DSC_0043.JPG is a scene from a product review session, so being able to save a picture as something like asus-product1.jpg is useful.  See Figure 2 for a screenshot of the terminal window showing the interactive command text and the flphoto (my choice) viewer application.

When you are all finished with your tethered session, use ctrl-c to leave the application.  Otherwise gPhoto will just do it's job and return to a command prompt.

What's Next?

gPhoto has a lot of options.  Since it runs from the command line, it can also be started from within cron and as a part of another script.  I have successfully used gPhoto and cron with the Plug Computer for short time lapsed photo capture.  gPhoto might also capture photos into a directory that feeds a Samba share or Web site album.  Send me your ideas and I'll try them out and then write a story about them.

Give tethered capture a try and see if it doesn't make your photography better.  I can't wait to go on my next photo taking session using gPhoto on my Netbook and a 20 foot USB cable.

This e-mail address is being protected from spambots. You need JavaScript enabled to view it
is a emerging technology consultant, writer, and portable computing expert. Tech trends, seminars, and writing projects are his stock-in-trade. His mission is to deliver exceptional value to his clients. Visit his Web site at

Click Here!