Month: December 2011

This was /almost/ an fantastic success in computing.  I gave myself about an two hours to start this project from scratch and it /almost/ performed flawlessly.

Here is what I wanted to do:

  • Connect and control our camera (Canon EOS 50) with a laptop.
  • Use my cellphone to trigger the pictures remotely so we could all be in the picture.
  • Preview the pictures from the place we were posed.
  • And store the pictures on the laptop.

First things first, I needed to get a new operating system on the laptop because it runs Microsoft Windows – and you can’t get anything done on that operating system. Well at least /I/ can’t get anything done.

I downloaded Ubuntu Linux and installed it on a 2GB usb thumb drive and booted up the laptop into a reasonable operating system. This is fantastic, I ran the entire computer off of a 2GB USB disk that made zero changes to the laptop. This is way I put up with Linux over even though it can be a harsh mistress some times.

So, Then I install a webserver (apache2) and a flurry of scripts that I run on my work computer.  One for renaming any image file to the date/time it was taken and some other convenience scripts for creating directories and what not.

I wrote a script using a command line program called gphoto2 (which by the way comes free with Ubuntu, just like the rest of it) to capture and download a picture from the camera and rename the photo.  Within about 20 minutes I could connect to the laptop’s command line (over ssh) from my phone and I could get the camera to take a picture.

Then I wrote a script for the web server that I could call with four different options: take pic, take 10, take 20, and take a delayed shot. It would also convert the last picture taken from each operation into a smallish picture that I could show as a preview.

The next step was to make my phone a “hot spot” so that the laptop could connect to it over WIFI.  Then I would be able to connect to the webserver on the laptop using my android phone.

So everything worked /almost/ great. Even while I was sweating and typing furiously I had little faith I was going to be able to get it all working before we needed it for the christmas card shoot.  And it worked fabulously except for a typo I had in my file renaming scheme that would assume that a completely new session started when the camera was unplugged and re-plugged.  So all and all we only got about 40 pictures automatically. 🙁

But I was able to take those pictures using my cellphone in an open, wet, dark, cold field from 100 feet away with only about an hour’s worth of hacking.

Some notes on implementing:

This was a live boot of linux and I showed a blatant disregard for security and at times threw in random privilege escalation to get things to run.

I had to edit the udev device creation scripts because the www-data user couldn’t get plugdev permissions no matter what I tried. So eventually I just made sure that the camera usually at /dev/bus/usb/001/007 was wide open.

Also I had to make sure that the desktop auto-mount bullish stuff didn’t take control of the device when it was plugged in. Which meant killing off any process called “gphoto2” and then taking away execute permissions on
/usr/lib/gvfs/gvfsd-gphoto2*

[this was a slasher/horror project for sure]

 

These are the scripts I ended up with in a zip file

———————————————————————————-

cat takepictures.cgi

#!/bin/bash
NUMPICS=`echo “$QUERY_STRING” | sed -n ‘s/^.*numpic=\([^&]*\).*$/\1/p’ |sed “s/%21/\!/g” | sed “s/%20/ /g” | sed “s/+/ /g”`
echo “Content-type: text/html

<!DOCTYPE HTML PUBLIC \”-//W3C//DTD HTML 4.01 Transitional//EN\”>
<html>
<head>
<title>Camera Control</title>
<meta http-equiv=\”Cache-control\” content=\”no-cache\”>
<meta http-equiv=\”Pragma\” content=\”no-cache\”>
</head>
<body bgColor = ‘#c0d8f4′>
<a href=’/cgi-bin/takepictures.cgi’><font size=’20’>HOME</font></a></br><br>
<a href=’/cgi-bin/takepictures.cgi?takenow’><font size=’20’>Take Now</font></a></br><br>
<a href=’/cgi-bin/takepictures.cgi?take10′><font size=’20’>Take 10</font></a></br><br>
<a href=’/cgi-bin/takepictures.cgi?take20′><font size=’20’>Take 20</font></a></br><br>
<a href=’/cgi-bin/takepictures.cgi?takepause’><font size=’20’>Take pause</font></a></br><br>

</form>

echo  “Last command: $QUERY_STRING<br>”
case  $QUERY_STRING in
takenow ) echo “Taking 1<br>”; /usr/lib/cgi-bin/picture >/dev/null;;
take10 ) echo “Taking 10<br>”; /usr/lib/cgi-bin/picture 10 >/dev/null;;
take20 ) echo “Taking 20<br>”; /usr/lib/cgi-bin/picture 20 >/dev/null;;
takepause ) echo “Taking 20<br>”; /usr/lib/cgi-bin/picture pause >/dev/null;;
* ) ;;
esac
sleep 1
echo “<br><br><h1>ALL DONE</h1>”

echo ‘</pre>

<a href=”/pictures/”>pictures</a><br>
<a href=”/pictures/latest_preview.jpg”><img src=”/pictures/latest_preview.jpg” /></a><br>
<br>

</body>
</html>

———————————————————————————-
cat picture
#!/bin/bash

cd /var/www/pictures

case $1 in
5 ) gphoto2 -I 4 -F 5 –quiet –filename %y%H%m-%S.jpg  –hook-script=/usr/lib/cgi-bin/hook –capture-image-and-download –camera=”Canon EOS 50D”  –port=”usb:” >/dev/null ;;
10 ) gphoto2 -I 4 -F 10 –quiet –filename %y%H%m-%S.jpg  –hook-script=/usr/lib/cgi-bin/hook –capture-image-and-download –camera=”Canon EOS 50D”  –port=”usb:”  > /dev/null ;;
20 ) gphoto2 -I 4 -F 20 –quiet –filename %y%H%m-%S.jpg  –hook-script=/usr/lib/cgi-bin/hook –capture-image-and-download –camera=”Canon EOS 50D”  –port=”usb:”  > /dev/null ;;
pause ) gphoto2 -I 8 -F 3 –quiet –filename %y%H%m-%S.jpg  –hook-script=/usr/lib/cgi-bin/hook –capture-image-and-download –camera=”Canon EOS 50D”  –port=”usb:” > /dev/null ;;
* )  gphoto2 -I 1 -F 1 –quiet –filename %y%H%m-%S.jpg –hook-script=/usr/lib/cgi-bin/hook –capture-image-and-download –camera=”Canon EOS 50D”  –port=”usb:”  > /dev/null ;;
esac
rm latest_preview.jpg
LASTPIC=`\ls -t1 *jpg| head -n1`
# convert comes with the imageMagick package that should be easy to get.
convert $LASTPIC -resize 640×480 latest_preview.jpg
echo “convert finished  <br><br>”

<hr>

———————————————————————————-

cat hook

#!/bin/bash
cd /var/www/pictures
case $ACTION in
init ) ;;
start );;
download ) /usr/lib/cgi-bin/image.getdate -p -M /var/www/pictures/$ARGUMENT ;;
stop ) ;;
* ) ;;
esac

 

After a long day of preforming Dexter likes to unwind with a good book and some cool milk

http://youtu.be/giamvSO7iDA

<iframe width=”560″ height=”315″ src=”http://www.youtube.com/embed/giamvSO7iDA” frameborder=”0″ allowfullscreen></iframe>