Search My Blog

Friday, October 8, 2010

On Ensemble : Masato Baba, Kristofer Bergstrom, Shoji Kameda and Kelvin Underwood » Blog Archive » Use an old digital camera, gphoto2, and Wordpress for automatic photo blogging

Use an old digital camera, gphoto2, and WordPress for automatic photo blogging

For the What We’re Eating feature of my blog, I needed a way to quickly take photos of our home-cooked meals. Using a dedicated camera and a simple script I wrote, the system prompts the user for a description of the meal, snaps the photo with the proper zoom and flash settings, rotates and resizes the photo, and uploades the content directly to the WordPress site so it’s immediately visible to the outside world… all with a single command! Read on to learn how to implement the system for your own automatic photo blogging!


Auto photo blogging with WordPress

The camera

The system uses a dedicated camera, permanently pointed at our dining area, connected to the computer by USB, and connected to a wall-socket for power. The camera must be supported by the gphoto2 software. I bought a used Canon Powershot G3 from a friend and it’s been perfect. An older, somewhat bulky camera, the G3 is less attractive than current models for day-to-day use but has great optics for high-quality shots.

gphoto2

gphoto2 is a command line application that allows you to control a USB-connected camera. Depending on the camera model, you can upload and download photos, set the picture quality, change the zoom and flash settings, and more.  On Debian or Debian-derived distributions (Ubuntu), the application is installed with the simple command “apt-get install gphoto2″.

Turn the camera on, connect it to your gnu/linux machine by USB, and run the following command to make sure the camera is recognized and can take pictures.

gphoto2 --list-config

This command will list the available control options for your camera and should output something like the following.


Detected a 'Canon:PowerShot G3 (normal mode)'.
/main/settings/ownername
/main/settings/capturesizeclass
/main/settings/iso
/main/settings/shutterspeed
/main/settings/zoom
/main/settings/aperture
/main/settings/exposurecompensation
/main/settings/imageformat
/main/settings/focusmode
/main/settings/flashmode
/main/settings/beep
/main/actions/syncdatetime
/main/status/model
/main/status/datetime
/main/status/firmwareversion
/main/status/driver
/main/Driver/list_all_files

Now test that the system can actually control the camera to take photos with the following commands.


cd /tmp/
gphoto2 --capture-image-and-download --filename test_photo.jpg

As the option names suggest, this will control the camera to take a photo and download the image immediately to the computer.

photoautoblog.sh

The photoautoblog command is a simple bash script that controls a digital camera to snap a photo of our dining table.  The photo is automatically manipulated and uploaded to my blog’s WordPress server, where it shows up in the header and is added to the list of our last 30 meals. The entire system is built on free software (and could use some improvement… please help!).

You can download the full script here:
photoautoblog.sh

Photo autoblogging in WordPress

The photos get uploaded to a directory on the server: /var/www/whatWereEating/ . From there, the images are utilized in two locations at my site. The most recent photo goes in the header of my blog, and images get added to the What We’re Eating post, which has photos of our last 30 meals.

Matt Gallizzi of NoTix Solutions helped me implement the auto-blogging stuff. He created a shortcode in /var/www/wp/wp-content/themes/default/functions.php as follows.

function what_we_are_eating() {  #/var/www/whatWereEating/  #http://onensemble.org/wp-content/whatWereEating/100711_121308_s.jpg         exec("ls /var/www/whatWereEating/*_s* -r |head -n 30",$recent_images);         $img_html="";         $date="";         date_default_timezone_set('America/Los_Angeles');         echo '<div stye="float: left; clear: both;">';         foreach($recent_images as $image) {                 $parts=explode("_",basename($image));                 if($parts[0] != $date) {                 #       $timestamp=date("l - F j, Y",filemtime($image));                         $stat=stat($image);                         $timestamp=date("l - F j, Y",$stat['mtime']);                         $img_html.="<div style=\"padding-top: 15px; clear: both; \">".$timestamp."</div>";                 }                 $info=file(str_replace("_s.jpg",".dat",$image));                 $img_html.='<div style="float: left; "><a style="float: right;" href="http://onensemble.org/wp-content/whatWereEating/'.basename(str_replace("_s ","_m",$image)).'" title="'.chop($info[0]).'"><img src="http://onensemble.org/wp -content/whatWereEating/'.basename($image).'" alt="'.chop($info[0]).'"></a></div >';                 $date = $parts[0];         }         echo '</div>';         return "$img_html"; }  add_shortcode('what_we_are_eating','what_we_are_eating'); 

The actual blogpost then simply calls that shortcode to generate the list of images. I added a break at the bottom to keep the "Share This" logo separated. The whole post content looks like this:


(Intro text here)

[what_we_are_eating]
<br style="clear: both" /> <br />

Note: The layout of this post is somewhat broken in older versions of Internet Explorer. I don't have IE here to test it but I'll be happy to help improve the script if someone cares.

The relevant bit of code from my header (/var/www/wp/wp-content/themes/default/category-13.php) looks like this:

<div class="header-section"> <div class="header-title">What We're Eating</div> <? exec("ls /var/www/whatWereEating/*_s* -r |head -n 1",$recent_images); $info=file(str_replace("_s.jpg",".dat",$recent_images[0])); echo '<div style="margin-top: 10px"><a href="http://onensemble.org/what-were-eating/" title="'.chop($info[0]).'"><img src="http://onensemble.org/wp-content/whatWereEating/'.basename($recent_images[0]).'" alt="'.chop($info[0]).'"></a></div>'; ?> </div> 

And finally, there are a few css definitions we created in /var/www/wp/wp-content/themes/default/style.css to define the layout of a few things:

.whatWereEatingText { text-align: right; font-size: 12px !important; margin: 0; padding: 0; } #kris-blog-header {                height: 16em;                min-width: 70em;                } .header-section {                   float: left;                   width: 19%;                   border-left: 1px none #999;                   margin: 1em 0;                   padding: 0 1em;                   height: 90%;                   } .header-section + .header-section {                                     border-left: 1px solid #999;                                     } .header-title {                 margin: 0 0 1em 0;                 } 

ShareThis

Tags: , ,

Go there...
http://onensemble.org/2010/10/use-an-old-digital-camera-gphoto2-and-wordpress-for-automatic-photo-blogging/

[gPhoto logo] Doc :: Remote controlling cameras

Remote controlling cameras


This page lists cameras remotely controllable for capture.
It is meant to be wiki-like, so if you have any additions, please mail them to gphoto-devel@lists.sourceforge.net mailinglist or to marcus@jet.franken.de.
The list is incomplete and might be incorrect.

If you start doing remote capturing, please begin by installing the latest libgphoto2 and gphoto2 stable releases, as remote control improvements and fixes are being added continously.


Configuring for capture

When doing remote capture you likely want to modify several on camera parameters.

The gphoto2 commandline frontend offers both a ncurses GUI mode (using --config) or scriptable commandline options to do configuration:

  • --list-config - This will list all possible configuration options.
    Please note that for some Canon cameras the complete list will only show after gphoto2 --set-config capture=on is run.
  • --get-config name - This will get the current configuration of name and its possible values.
  • --set-config name=value - This will set the configuration of name to value.

Most of them are self explaining, but some interesting ones:

  • Canon cameras only: capture - setting this to on will extract the lens and make it read for SDRAM based capture. Setting it off will retract the lens again.
  • Canon and some Nikon cameras only: capturetarget - setting this to sdram will make the camera capture directly into the camera RAM and not on the memory card. You need to download the image in the same gphoto2 call, otherwise it will gone when the connection is closed. Use --capture-image-and-download to capture and download instantely.
    Set it to card to capture to the memory card.

Continuous / Interval capture

The options -F frames and -I seconds can be used to support continuous capture. -F 0 will capture images ad-infinitum.

This can be used with either --capture-image which would leave all images on the card, or --capture-image-and-download which captures and downloads the images immediately.

List of cameras


Camera Name Libgphoto2 capture support Controllable aspects Megapixel Notes
Canon Digital IXUS II/PowerShot SD100 Yes Quality, Imagesize, ISO, Whitebalance, Photoeffect, Zoom, Assistlight, ExpComp, Flashmode, Aperture, Focuspoints, Shutterspeed, Metering Mode, AF Distance, Focus Locking, Viewfinder 3  
Canon PowerShot SD110 Yes All (like SD100),Viewfinder 3  
Canon Digital IXUS 400 Yes All,Viewfinder 4  
Canon Digital IXUS 430 / ELPH S410 Yes ?,Viewfinder 4 In PTP mode
Canon IXY Digital 300 Yes All,Viewfinder 2  
Canon EOS 1000D / Rebel XS / Kiss F Yes Image Format, ISO, WhiteBalance, Whitebalance Adjust, DriveMode, Picture Style, Bulb Mode, BracketMode, Aperture, ShutterSpeed, Autofocus (in LiveView mode), Manual Focus (in LiveView mode), Viewfinder 10 Use libgphoto2 2.4.9
Use the Modewheel on the Camera to get to different settings.
Shutterspeed and Aperture not available in Auto or P setting, only in the more manual ones.
For Bulb mode: Switch dial to 'M'anual mode, gphoto2 --set-config shutterspeed=bulb , and run something like: gphoto2 --set-config bulb=1 --wait-event=10s --set-config bulb=0 --wait-event-and-download=5s
Canon EOS 300D/Digital Rebel Yes ISO, Shutterspeed, Zoom (? likely read only), Aperture, Resolution (RAW, Normal JPEG, ...), Focus Mode (read-only?), Flash Mode (read-only) 6.5 Uses "Normal" mode in the camera (and the "canon" driver in libgphoto2). Set Modewheel to "M" to get all settings.
Canon EOS 40D Yes limited level of configurability (see EOS 1000D), Viewfinder 10.1 use libgphoto2 2.4.9
Canon EOS 400D / Rebel XTi / Kiss Digital X Yes limited level of configurability (see EOS 1000D), no Viewfinder 10.1 use libgphoto2 2.4.9
Canon EOS 450D / Rebel XSi / Kiss X2 Yes Image Format, ISO, WhiteBalance, DriveMode, Picture Style, Aperture, Shutterspeed, Viewfinder 12 Use libgphoto2 2.4.9. Use the ModeWheel on the Camera to get to different settings. Shutterspeed and Aperture not available in Auto or P setting, only in the more manual ones.
Canon EOS 50D Yes limited level of configurability (see other EOS), Viewfinder 15.1 Use libgphoto2 2.4.9. Use the ModeWheel on the Camera to get to different settings. Shutterspeed and Aperture not available in Auto or P setting, only in the more manual ones.
Canon EOS 500D / Rebel T1i / Kiss X3 Yes limited level of configurability (see other EOS), Viewfinder 15.1 Use libgphoto2 2.4.9. Use the ModeWheel on the Camera to get to different settings. Shutterspeed and Aperture not available in Auto or P setting, only in the more manual ones.
Canon EOS 550D / Rebel T2i / Kiss X4 Yes limited level of configurability (see other EOS), Viewfinder 18.0 Use libgphoto2 2.4.9. Use the ModeWheel on the Camera to get to different settings. Shutterspeed and Aperture not available in Auto or P setting, only in the more manual ones.
Canon EOS 5D Mark II Yes see other EOS like 1000D, Viewfinder 10.1 use libgphoto2 2.4.9
Canon EOS 7D Yes ImageFormat, ISO, WhiteBalance, WhiteBalanceAdjust, DriveMode, PictureStyle, Aperture, Shutterspeed, MeteringMode, BracketMode, AutoExposure Bracketing, Viewfinder 18 Use libgphoto2 2.4.9. For Bulb capture turn rotary dial to 'B'.
Canon PowerShot A10 Yes unknown, Viewfinder 1.3  
Canon PowerShot A100 Yes unknown, Viewfinder 1.2  
Canon PowerShot A20 Yes unknown, Viewfinder 2.1  
Canon PowerShot A200 Yes unknown, Viewfinder 2  
Canon PowerShot A30 Yes unknown, Viewfinder 1.32  
Canon PowerShot A300 Yes All, Viewfinder 3.2  
Canon PowerShot A310 Yes All, Viewfinder 3.2  
Canon PowerShot A40 Yes unknown, Viewfinder 2  
Canon PowerShot A400 Yes ImageQuality, ImageSize, FlashMode, ShootingMode, DriveMode, Zoom, MeteringMode, AF Distance, FocusingPoint, WhiteBalance, ISO, Aperture, ShutterSpeed, ExpComp, PhotoEffect, AssistLight, Focus Locking, Viewfinder 3.2 From reporter. Only captures with PTP driver.
Canon PowerShot A510 Yes All, Viewfinder 3.2  
Canon PowerShot A520 Yes All, Viewfinder 4  
Canon PowerShot A60 Yes Unknown, Viewfinder 2  
Canon PowerShot A620 Yes Unknown, Viewfinder ?  
Canon PowerShot A640 Yes ImageQuality, ImageSize, ISO, WhiteBalance, AssistLight, ExpComp, FlashMode, ShootingMode, Aperture, Shutterspeed, FocusingPoint, MeteringMode, AF Distance, Focus Locking, Viewfinder 10 One reference user: oldcapebridge.com
Canon PowerShot A70 Yes ImageQuality, ImageSize, FlashMode, ShootingMode, DriveMode, Zoom, MeteringMode, AF Distance, Focusing Point, WhiteBalance, ISO, Aperture, Shutterspeed, PhotoEffect, Focus Locking, Viewfinder 3 (from ptpcanon list)
Canon PowerShot A75 Yes Unknown, Viewfinder 3 from capture.sf.net notes
Canon PowerShot A80 Yes All, Viewfinder 4 capture.sf.net and user reported
Canon PowerShot A85 Yes All, Viewfinder 4
Canon PowerShot A95 Yes ImageQuality, ImageSize, FlashMode, ShootingMode, DriveMode, Zoom, MeteringMode, AF Distance, Focusing Point, WhiteBalance, ISO, Aperture, Shutterspeed, ExpComp, Focus Locking, Viewfinder 5 from capture.sf.net notes
Canon PowerShot A520 Yes All, Viewfinder 4 from capture.sf.net notes
Canon PowerShot A620 Yes All, Viewfinder 7  
Canon PowerShot A640 Yes All, Viewfinder 10  
Canon PowerShot G1 Yes Unknown 3.3  
Canon PowerShot G2 Yes Unknown 4  
Canon PowerShot G3 Yes Unknown, Viewfinder 4  
Canon PowerShot G5 Yes ImageQuality, ImageSize, ISO, WhiteBalance, PhotoEffect, Zoom,AssistLight, ExpComp, Aperture, FocusingPoint, ShutterSpeed, MeteringMode, AF Distance, Viewfinder 5  
Canon PowerShot G6 Yes All, Viewfinder 7.1  
Canon PowerShot G7 Yes All, Viewfinder 10  
Canon PowerShot G9 Yes ImageSize, ISO, WhiteBalance, Zoom, AssistLight, ExpComp, FlashComp, FlashMode, ShootingMode, Aperture, FocusingPoint, ShutterSpeed, MeteringMode, AF Distance, Viewfinder 12  
Canon PowerShot G10 Yes All, Viewfinder 14.6  
Canon PowerShot Pro 90 IS Yes Unknown, Viewfinder 2.6  
Canon PowerShot S1 IS Yes All, Viewfinder 3  
Canon PowerShot S2 IS Yes All, Viewfinder 5  
Canon PowerShot S3 IS Yes All, Viewfinder 6 confirmed by Canon
Canon PowerShot S5 IS Yes All, Viewfinder 8 confirmed by user with 2.4.0
Canon PowerShot S40 Yes All, Viewfinder 4  
Canon PowerShot S10 Yes Unknown, Viewfinder 2.1  
Canon PowerShot S20 Yes Unknown, Viewfinder 3.2  
Canon PowerShot S30 Yes Unknown, Viewfinder 3.2  
Canon PowerShot S40 Yes Unknown, Viewfinder 4  
Canon PowerShot S45 Yes All, Viewfinder 4  
Canon PowerShot S50 Yes All, Viewfinder 5  
Canon PowerShot S60 Yes All, Viewfinder 5 See sample installation
Canon PowerShot S70 Yes All, Viewfinder 7  
Canon PowerShot S80 Yes All, Viewfinder 8  
Canon PowerShot S100 Yes Unknown, Viewfinder 2  
Canon PowerShot S110 Yes Unknown, Viewfinder 2  
Canon PowerShot S200 Yes Unknown, Viewfinder 2  
Canon PowerShot S230 Yes All, Viewfinder 3  
Canon PowerShot S300 Yes Unknown, Viewfinder 2  
Canon PowerShot S400 Yes All, Viewfinder ? from capture.sf.net notes
Canon PowerShot S410 Yes All, Viewfinder ? from capture.sf.net notes
Canon PowerShot S500 Yes All, Viewfinder ? from capture.sf.net notes
Canon PowerShot SD110 Yes All, Viewfinder 3  
Canon PowerShot SD430 Yes, but only over WLAN All, Viewfinder 5 Unfortunately the WLAN (PTP/IP) mode to connect to this camera is not working yet.
Canon PowerShot SX100 IS Yes Zoom, ISO, Quality, ImageSize, WhiteBalance, ExposureCompensation, FlashCompensation, CaptureMode, Aperture, Shutterspeed, MeteringMode, AF Distance,, Focus Locking, Viewfinder 8 1 frame capture and download - 2-3 seconds
Canon PowerShot SX110 IS Yes All (likely same as SX100IS above), Viewfinder 9  
Canon 20D, 350D/Digital Rebel XT Yes All 8.2 Needs 2.4.0 or newer
Canon 5D Yes All 12 Needs 2.4.0 or newer
Casio EX-F1 Tethered Unknown 6 Only tethered shooting, Firmware 2.0 required.
Nikon CoolPix 880 Yes All ?  
Nikon CoolPix 2500 Yes All 2 In Sierra mode (USB Mass storage pass through)
Nikon CoolPix 4300 Yes All 4 In Sierra mode (USB Mass storage pass through)
Nikon CoolPix 4500 Yes All(?) 4 Only with updated firmware, see here
Nikon CoolPix 5000 Yes All 5  
Nikon CoolPix 5400 Yes Unknown 5  
Nikon CoolPix 5600 Yes All,no focus, no aperture 5  
Nikon CoolPix 5700 Yes All 5  
Nikon CoolPix 5900 Yes All 5  
Nikon CoolPix P1 Yes Some 8 Only over USB, not over PTP/IP.
Nikon CoolPix P2 Yes Some 5 Only over USB, not over PTP/IP.
Nikon CoolPix P3 Yes Some 8 Only over USB, not over PTP/IP.
Nikon CoolPix P5000 Yes None 10 only image quality configurable
Nikon D40 Yes All 6  
Nikon D40x Yes All 10  
Nikon D50 Yes All 6  
Nikon D60 Yes All 10  
Nikon D70 Yes All 6  
Nikon D70s Yes All 6  
Nikon D80 Yes All 10  
Nikon D90 Yes All, Viewfinder 12  
Nikon D200 Yes All 10  
Nikon D300 Yes All 12  
Nikon D3000 Yes Basic set of abilities (no SDRAM, no Viewfinder, just the basic capture settings) 10  
Nikon D700 Yes All, Viewfinder 12  
Olympus C750UZ Yes All ?  
Olympus C-2040Z Yes All 2  
Olympus C-2100Z Yes All 2  
Olympus C-3040Z Yes All 3  
Olympus C-4040Z Yes All 4  
SQ905 chipset cameras (check list in C file here) Yes ? 320x240 pixel, 160x120 pixel, some also 640x480 pixel  
Digigr8 chipset cameras (check list in C file here) Yes ? 320x240 pixel  
STV680 chipset cameras (check list in C file here) Yes None 320x240, 160x120, sometimes also 640x480 pixel  

If a camera is not listed, it might still be the case that is able to support capture.

For instance, it is a very good sign if the vendor supplies software that supports remote capture for this camera. Those are likely able to be supported by libgphoto2 if not already.


Cameras not able to do capture

Name Comment
Kodak EasyShare Any None of those supports remote capture.
Sony Cybershot DSC (PTP) None of those supports remote capture.
Fuji Finepix (PTP) Most of these cameras do not support remote capture. Some professional Fuji S* pro cameras might support it, please see the Utility tool page.
Various Canon cameras: All Powershots released after mid 2009 are not capable of remote control anymore.

Statement from Canon SDK: As a reminder: PowerShots A410, A420, A430, A450, A460, A470, A530, A540, A550, A560, A570 IS, A580, A590 IS, A610, A630, A650 IS, A700, A710 IS, A720 IS, A1000 IS, A2000 IS, S10, S20, S330, SD10, SD20, SD30, SD40, SD200, SD300, SD400, SD430, SD450, SD500, SD550, SD600, SD630, SD700 IS, SD750, SD770 IS,SD790 IS,SD800 IS, SD850 IS, SD870 IS, SD880 IS, SD890 IS, SD900, SD950 IS, SD990 IS, SD 1000, SD1100 IS, SX 1 IS, and SX 10IS do not support remote control or video out operation via the SDK.
The same applies for libgphoto2 capture support.

Also see this Canon page for a overview of which cameras are supported and which are not as of April 1st 2008.

Minolta Dimage Z2 Do not support remote control. See Konica-Minolta FAQ

Don

No comments: