Schedule Photo Taking With gPhoto and cron

959

gPhoto is a program that controls a digital camera from a Linux machine. cron is the tried and true job scheduling program that has been a part of Unix and Linux since the beginning. Put those together with your camera and small footprint Linux machine and you can take all kinds of regularly timed photographs.

Perhaps you are putting up a building and want to capture the action, at a regular time over the next few months. You could use an inexpensive point and click digital camera and an old laptop to capture a photo every day at 10 AM. The individual photos could be used to create a video or slide show documentary of the work.

Sure. you could use a $40 USB Webcam to grab those pictures, but you won’t get the detail or have any flexibility to change the ISO, aperture, or shutter speed, to compensate for different conditions.

gPhoto along with cron is easy to use and offers a lot of possibilities.

gPhoto Reviewed

gPhoto is a command-line camera control program for Linux systems. It can trip the shutter, using a USB connected Linux machine, for a reported 1000 different digital camera models. Depending on the camera, you can also manipulate on-board settings with a wide variety of options.

Here is the general form of the command.

rreilly> gphoto2 --option

Some of the interesting options include –capture-image, –set-config, and –interval. Capturing an image is straightforward.

rreilly> gphoto2 --capture-image

This command line will trip the shutter on the camera and a new photo will be saved on the camera’s memory card. Photos will accumulate on the card and can then be downloaded to the Linux machine later. Figure 1 shows the –capture-image and –get-all-files options, together.

Schedule With Cron

A quick review of cron is probably in order. cron is the main table driven job scheduler for Linux. Entries are added to the file to control when a command runs. It is accurate to whole minutes. You can use the following command to edit the table that controls cron.

 

rreilly> crontab -e

 

You can change the default editor for cron using this line. I like vi, but you can use whatever you like. I even tried using OpenOffice.org. That was interesting.

rreilly> export EDITOR=vi

You’ll see text something like this.

PATH=/usr/sbin:/usr/bin:/sbin:
/bin
# m h dom mon dow command

The m and h represent the minutes and hour of the day, that the command will run. As you might expect dom, mon, and dow map to day of the month (1-31), the month (1-12), and day of the week (1-7), respectively. You can use just about an command imaginable. Multiple values are separated with commas.

Using gphoto with cron is pretty simple. The following is an example that takes a picture at 50, 52, 54, and 56 minutes after the hour.

PATH=/usr/sbin:/usr/bin:/sbin:/bin
# m h dom mon dow command
50,52,54,56 * * * * gphoto2 --capture-image

The photos will be saved on the camera’s card using the default numbering scheme. On my Nikon, the files might be named something like DSC_0000.JPG through DSC_0003.JPG. cron will use the newly edited table as soon as it is saved, so you’ll want to plan ahead a little and not be editing the table during the scheduled execution time.

Timed picture taking sessions spanning days, weeks. or months will require that the camera have an external power supply, since batteries simply won’t work for such long time periods.
Getting the files off the camera is just as easy and can be incorporated into cron as well. Just add a download line.

01 01 * * * gphoto2 --get-all-files

This will download all the files on the camera to your home directory at 01:01:00 every day.

For an in-depth discussion, this Ubuntu cron “how-to” is pretty comprehensive.

Additional Possibilities

I’ve used gphoto and cron to capture photos with my Asus laptop. That works fine, but is a little limiting because laptops take up a good amount of space. Mounting a laptop on a little portable stand and putting the camera on a tripod works, especially in a studio shooting situation. I’ve seen a few pros doing it that way. On the other hand, a little Netbook, running eeeBuntu would make good sense for portable, regularly timed automated shooting at events or conferences.

gphoto and cron with the Plug Computer and my Nikon works too, although you need an additional machine to remotely log into the Plug Computer. Capturing photos using cron, in this mode is a no brainer, but I’ve only scratched the surface with this combination. The Plug Computer is relevant because it is cheap ($US 99), has a small footprint, is network enabled, and runs Ubuntu Linux. I have a lot of projects in mind for this nano machine.

Another interesting, but less flexible way to take regularly scheduled pictures is to use gphoto with the –interval option. This could be combined with cron to take a short burst of photos, at a certain time of day, perhaps to bracket the shot. An example of the basic –interval command line might be the following.

rreilly> gphoto2 --capture-image --interval=5 --frames=5

 

Here, five images at five-second intervals are captured. The images download to the laptop’s home directory using a sequential naming convention. When I used this setup with my Nikon, the files were named capt0000.jpg through capt0004.jpg.

You’ll probably want to make sure that you always use a reasonable value for the –frames option with –interval, otherwise the computer will continue to shoot photos indefinitely until all the space on the memory card is consumed.

Another thing to consider with this option is battery life. Battery power differs considerably across the various brands and models of cameras. Using the flash also affects the number of images that you are able to capture. The standard on-board battery in my Nikon is good for between about 40 and 50 shots using the flash. Obviously, if you want to take 300 pictures external camera power is essential.

Wrap Up

Combining gphoto and cron opens up automated shooting with a minimum of equipment and a little set up. I can see where students, researchers, astronomers, and photographers could put it to good use. Being able to execute programs with a multi-tasking, multi-user system is one of the hallmarks of Linux. While possible on other systems, you sure can’t beat the logic and ease of use with Linux.

Give gphoto and cron a try. Share any new combinations that you discover and be sure to have fun with it.

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. Early adopter 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 http://home.earthlink.net/~robreilly.