Tuesday, June 4, 2013

23. Making Time Lapse Sequences with the Pi Cam

The first thing I had to do was to find a way of transferring files from the Pi to my PC.  Up until now I have been emailing them to myself from the Pi and picking them up on the PC - a bit primitive, and not very practical for files bigger than 25 MB (the email limit) or for a large number of files.

I came across WinSCP (Secure Copy Protocol for Windows).  This was very easy to install and run, and it works great!  You can easily download it free from winscp.net.  Here is a screenshot of the setup window:



I just ignored the Private key file and Select color options as I don't know what they are for.  When you click Login, you get a screen like this:



It's magic!  On the left pane are my PC files and on the right, the Pi's files.  That's pretty impressive, as the PC is on Windows, and the Pi is on Linux.  To transfer files from one machine to the other, you can drag 'n drop or highlight and move - brilliant!  If you look carefully, you'll see a series of files on the Pi named a_00001_1min.jpg to a_00010_1min.jpg.  These are my very first attempt at time lapse photography and I'll tell you more about these below.

I got the instructions from the very helpful Alex Eames of RasPiTV at http://raspi.tv/tag/raspicam-nine-day-time-lapse-video

So to get a 1-minute time lapse sequence of jpegs, each representing a 6 second interval, I ran the following command:

raspistill -t 60000 -hf -w 1920 -h 1080 -tl 6000 -o a_%05d_1min.jpg
By way of explanation,
-t 60000 is the number of milliseconds in 1 minute - the period the program runs for.
-hf is horizontal flip (to reverse the mirror reflection effect)
-w 1920 -h 1080 width and height for 1080p video output. There's no point in recording at the absolute maximum still image size of 2592 pixels by 1944 pixels, as HD video is happy with 1920 x 1080 pixels.
-tl 6000 is the number of milliseconds between shots (6 seconds)
-o a_%05d_1min.jpg is the option to name the output file.  The %05d part gives you a 5 figure integer padded with leading zeros. So, the first one will be 00001, and the tenth would be 00010. 
Each jpeg produced is about 1 MB in size.  I used WinSCP above to transfer the series of images to the PC and I then used my old friend ImageJ to process the images:

This very useful (free) Java-based program is great for all sorts of image processing, and you can write your own Java macros to do exactly what you want with images.  I read the series of jpegs into ImageJ and asked it to produce a stack, to play at 3 fps.

Then I saved the stack as an animated GIF file.  This format is suitable for playing on browsers, including Safari on iOS devices:

What you are seeing here is a demonstration of my Darkness Detector which uses the Darlington Pair of transistors (See Post 17 on this Blog - HERE) - exciting stuff!!

My next task is to run my Pi headless (ie without a monitor, as I want to move my Pi to a window for recording more exciting time lapse exposures) and to do this I need to be able to control it through SSH - ie see its desktop on my PC (See Post 21 on this Blog - HERE).

Hey Presto!  Running Xming and PuTTY works!!  I can now control my headless Raspberry Pi which is upstairs, with my downstairs PC, using the wireless network.

Here's my next attempt at time lapse - a 12 hour sequence (with the black night-time images removed):

Unfortunately it's a little crooked, but it's quite difficult to guess how straight the camera board is when taped to the inside of a window.  It also has lost a lot of image quality in the conversion to a movie.

Watch out for the early bird flying past at about 5 am, and then another - and the tide coming in - and the ship going past - and then another.

Here's another time lapse sequence of some blue tits on my bird feeder.  (Must fill up with peanuts soon):
I used ImageJ in macro mode to crop to 769x769 pixels, a series of 44 exposures taken at 2 minute intervals,  and I enhanced contrast to remove some of the glass reflections from my window.

Now wouldn't it be nice to have a proximity monitor (PIR detector?) to trigger the recording?

Here's a couple more:

1 comment:

  1. Hi Da, Looking really good! Coming on in leaps and bounds!Was thinking a time lapse around sunset would be really cool as well... Love the darkness detector too...!

    ReplyDelete