High Dynamic Range (HDR) Imaging on the #n900 Using Gstreamer and Enfuse
I am constantly finding new and interesting things to do with my Nokia N900 phone and the latest is HDR photography. It took a little work to get it going, but I now have my first HDR photographs.
I started off by reading the thread HDR Pictures with the N900?. It pointed to an article about HDR and Python. The article looked promising and talked about using CHDK and exposure bracketing. I have CHDK running on my Cannon camera, but wanted to find out what is available on the N900 similar to CHDK.
In looking around a little bit more, I found simple intervalometer for the N900 (time-lapse photography). This uses gstreamer and was used as part of the Kite Aerial Photography project. Note to self: kite aerial photography looks like another very cool and interesting project.
So, I installed gstreamer-tools:
apt-get install gstreamer-tools
and tried to figure out how to make it work.
One of the KAP posts suggested using this stream:
gst-launch v4l2camsrc device=/dev/video0 num-buffers=1 ! omx_jpegenc ! filesink location=MyDocs/interval-001.jpg
So, I tried it, and it didn’t work. Since then, I’ve spent a little time learning how gstreamer works. Essentially, you set up pipes. Information comes from a source, goes through a set of pipes and ends up at a sink. In this case, the source is v4l2camsrc and it is using the device /dev/video0. You can use all kinds of different sources and devices. The N900 has two cameras in it, /dev/video0, which is the 5 megapixel camera, and a smaller camera on the front, /dev/video1 I’ve never had a lot of luck with /dev/video1 and for my purposes, I want to use the main camera.
Another source is v4l2src which also uses /dev/video0. So far, it appears as if v4l2camsrc is quicker, but only produces 640x480 images. V4l2camsrc seems to hang for about 7 seconds for me with a message, New clock: GstSystemClock before it takes the picture. If I can find out how to get around this, it will make things better.
For non camera sources, you can use filesrc to read files and send them down the pipeline. This is another area I need to explore.
On to the pipe, I could not find “omx_jpegenc”. Other options are jpegenc, pngenc and dspjpegenc. However, some of them take different sources, and you have to make sure you connect them properly.
A bit more poking around revealed that if you stick ffmpegcolorspace between v4l2src and pngenc you can then wave the files, so
gst-launch v4l2src! ffmpegcolorspace ! pngenc ! filesink location=MyDocs/interval-001.png
should save a picture.
The next problem to be dealt with was how do you control the exposure? Davost handled this quite nicely with a very simple c program for setting exposure levels. (You can find his tarball in the fourth page of the HDR thread.) Essentially, if you run his program expcomp it changes the exposure settings. So, if you run it, together with gst-launch several times, you can get the pictures you want.
With this installed, I then started taking some pictures. In his sample script, he took three photographs with exposure levels of -2, 0 and +2. I modified the script to take five photographs with exposure levels of -4, -2, 0 , +2 and +4. Using sshfs, I then copied the files over to my Linux laptop. My Linux desktop is running Hardy Heron, and I couldn’t install enfuse, the program that davost had recommended, but I could install it on the laptop which is running karmic koala.
apt-get install enfuse
With enfuse running on the laptop and the png files copied over from the N900, it because easy to create the HDR file. I used the command
enfuse –o hdr.jpg rawHDRtest_0.png rawHDRtest_1.png rawHDRtest_2.png rawHDRtest_3.png rawHDRtest_4.png
I’ve put a few sample pictures up on my Flickr Page.
Since then, I’ve started exploring other things that can be done with gstreamer on the N900. I’ve played music and displayed computer generated effects to go along with it on my TV as output from the N900. I’ve started to look at other music and video options with gstreamer.
So, I’m off to learn more about how to use gstreamer on the N900 and generate even more interesting sounds, images and videos. Yeah, it’s a little geeky to set this up, but it is fun to take controlling your phone and camera to a new level.