Friday, March 22, 2019

Timelapse Camera With Raspberry Pi

I thought I could make quick work of getting some timelapse footage around the house by connecting up a new Raspberry Pi 3 B+ with a v1.3 camera module I had. Being lazy and impatient I wanted to avoid writing a whole program for it in Python and just start captures by running raspistill commands in terminal with a headless setup.
But a day and lots of debugging later I ended up going with a Python program after all. Here is a Twitter thread detailing all the problems I encountered, and that was after I figured out how to get the camera's ribbon cable installed the right way.

So I ended up working from tips off the picamera Python module documentation to make a program that takes any number of pictures you want at whatever interval:
link to code
EDIT: To use the program, you can first find out the different required and optional flags by typing "python timelapse.py" in the location where it resides:
Type "python timelapse.py -h" for a more verbose explanation:
So, at a minimum you have to run it with an interval and number of frames ("python timelapse.py -i 5 -n 20" for a minute of captures every 5 seconds), but as you can see you have control over whether the image is flipped horizontally and vertically, ISO setting, and whether to overlay a timestamp. I fortunately came across argparse which made providing such options with the script so easy.
I used scp to copy the pictures over to my computer:
scp pi@192.168.10.110:~/Desktop/images/* ~/images/
Then I used ffmpeg to stitch together the images into a video, detailed in this previous post:
ffmpeg -framerate 5 -i ~/images/image%04d.jpg -pix_fmt yuv420p video.mp4
The final result, some taken with raspistill and the last with the Python script:



No comments :