Astrophotography Using Canon Camera’s Hack Development Kit August 16, 2009Posted by GuySoft in Astronomy, Crictor, diy, Hamakor, ITU, linux, open source, programming.
Tags: Astronomy, basic, camera, chdk, diy, ffmpeg, hacking, meteors, negev, open source, programming, video
I am going to explain here how I managed to use the Cannon open source hack development kit , known as CHDK, to photograph stars and even create neat movies of the stars motion.
It all started this Monday, I was lucky to see that there is going to be Perseids meteor shower, a day in advance. So I had time getting the code ready before it was too late. I thought I would go somewhere next to Jerusalem and photograph, but in the end, friends of mine (Shy and Anna) from the Israeli Astronomy Association, which I am part of, told me they are going down south to the dessert, far away from light pollution, to take count of the meteors for the IMO. So I joined him, and my data is also available.
Before all the technical stuff, here is a video I made that shows you what this all comes to:
Now back to CHDK, and how this was done.
What is CHDK? And how do I install it?
CHDK is a firmware addon for Cannon powershot digital cameras. It supports most of them, mine is a simple powershot A590, costs to date about 700 NIS. Moreover, since its an addon, it will not void warranty, and can’t damage your camera. It has a lot of features (including games and an e-book reader!).
Installing it is really easy and comes the complete version comes with everything you need. All you do is extract the version for your camera on your SD card. Then start the camera in the review mode, and select in the menu ‘Firm Update…’, Look at CHDK’s wiki for more info.Now that CHDK is running, pressing the (used to be useless) printer button on your camera. It will bring an <alt> symbol at the bottom of the screen, meaning all buttons will control the options of CHDK. Pressing the printer button again will move you back to use the camera menus. Restarting the camera will wipe out CHDK from the memory (you need to do ‘Firm Update’ again, to use it again). So if you want to stop CHDK, just turn the camera off and on. Uninstalling is just removing CHDK’s files from the card.
My Basic Ubasic application
Once I got CHDK running, and after looking around the menus and confusing people by playing Reversi on my camera, I started looking in to the scripting capability.
One can write scripts both in ubasic and lua. I wrote mine in ubasic, although I never wrote in ubasic/basic before, it was dead easy to pick up. I choose ubasic because some developer told me lua has some timing problems. Both languages don’t need compilation, just write a text file and put it in the /CHDK/SCIPTS folder in the SD and they will run. To run a script select the ‘load script’ option, when in <alt> mode. Now, when in standby mode, using the capture button will run the selected script, and not just photograph as normal.
The programming commands I got mostly from this tutorial. Note how easy it is to let the user to have configurable parameters, print stuff on the screen, and shoot images. You can also change parameters of the camera using PropertyCase commands (see my code to see how it is used).
My meteor script, avilable here, it basically (pun!) starts the camera, disables flash and goes in to loop shooting images on a given ISO and exposure time until the shooting button is pressed again. You can see the selection interface on the right (sorry for the typo on the word Meteor, it was late). If you use my script then you better disable the screen display before shooting, and the review time, so at night, all you see is a blinking led telling you the camera us working (was ok for the astronomer standard too). The camera lasted about an hour of photographing before the batteries ran out. Luckily I had about 4 pairs of AA batteries. There is much to improve in the script, but it works.
Processing Animations with FFmpeg
Sadly, I did not catch any meteors in any of my 700 images. I think I did not set the aperture to be open all the way, I expected it will do it in a dark setting.
However, connecting all the images together gave me an animation of the moving sky Using FFmpeg. It seems that FFmpeg is a bit picky about its file formats. So here is how to take your jpg images and turn them to a movie:
- You will need to download all your images to a single folder.
- Run this bash script I wrote, it will make an ‘out’ folder in the folder, and copy all the files numbering them 000.jpg 001.jpg etc. Like FFmpeg likes, otherwise ffmpeg segfaults (thanks to #ffmpeg on freenode for the guidlines):
- After the jpg images ready, you can run FFmpeg with this command in your folder:
ffmpeg -r 24 -f image2 -i %3d.jpg -b 700000 -s 720x480 output.avi. Note you can change resolution there, bitrate, and do anything ffmpeg does. Since the images are in a camera quality you can even do HD video with a cheep camera!
- Thats is, you have a time lapse video
# Not enough information to compute
if [ $# -lt 1 ]; then
echo "Syntax: `basename $0` "
#if dir exists, then go over all files and copy them
if [ $# -eq 1 -a -d "$1" ]; then
mkdir -p $1/"out"
for file in $1/*.[jJ][pP][gG]
cp "$file" $1/out/$(printf "%0.3d.jpg" $i)
i=$(( $i + 1 ))
List of videos using this script. I also made a page for them here.
- Orion, Venus and Sunrise (my favorite)
- Scorpius setting
- Polaris time lapse
- Cassiopeia time lapse
- Cygnus time lapse
CHDK seems to have many new ways to take a simple camera, one you might even already have, and do things you never thought possible on a normal camera. Maybe next I’ll try using RAW imaging, that will let me get even better views of the stars.
And thanks to Anna and Shai for a wonderful night
Update: There is a forum thread in CHDK’s website about the blog post with even more talks.