Time lapse using raspberry pi camera

Hi guys,

Is there anyone in this group who can share their knowledge about making a thread of using the picamera with a function of timelapse? Is there any libraries available?

Our aim is to create multiple threads that would make the picamera function as:

  1. Plain camera
  2. Photo delay
  3. Burst photos
  4. 10-sec video
  5. 1-minute video
  6. CCTV with motion sensor and push email notification And lastly,
  7. Timelapse

The last two parts are still not yet configured since all codes that we can search are python codes. Thank you so much!

Reply to
anngarcia187
Loading thread data ...

I've done timelapse with a Pi, Python and three image processing programs to do the manipulation. Normal python to tell the camera to take a still, image processing to see if there is a useable image or not (timelapses of black frames at night aren't very interesting), more image processing to add a date/time stamp. Every 6 hours kick off ffmpeg (IIRC) to make the timelapse from all the previous stills. IIRC I took a still every 30 seconds, the time lapse would run a couple of minutes but take several hours to render. Python "wrapper" to maintain the filestore and call the programs as required

This was all at Full HD (1920 x 1080), worked quite well but it doesn't half hammer your SD card or USB stick. It killed an SD card in about 6 weeks and a USB stick in not much longer. Some form of robust file storeage is required, like a proper hard disk.

--
Cheers 
Dave.
Reply to
Dave Liquorice

I've been using pis for timelapse for a few years just using raspistill from a shell script. I've been wanting to rewrite my script for as long as I've been using them to make them more robust and easier to use, but it certainly does the job. So, yes, I'm very interested in the conversation, but I don't know that I can offer a lot other than to describe my hacked together setup.

My typical setup is 3 or 4 pis (As and Bs) that boot and then start running the same script. The pis each get their name from their network interface. They look for a server (my laptop - hardcoded into the script) and get the current time from there and basic parameters (frequency of shots). Then they snap pics at whatever rate they've been directed to. Rsync runs in the background to make sure my laptop always has the latest shots so if something goes wrong or cameras break or disappear (has never happened, but I tend to use them in public places), I have all photos already taken.

So what I'd love to do that someone else suggested, but I never did it, was set up the pis so that they form a mesh network. I shouldn't really need a router or wifi extenders which I use now. Whichever one turns on first can act as a server or otherwise drive the behavior of the others (at least provide a time server so they're in sync). They should have some sort of mechanism to reconnect to the network or cleanly handle one disappearing. Even if my laptop continues to be the ultimate destination for the files, it would be nice if it didn't matter what order things turned on. Right now, if my laptop isn't reachable, the camera behavior is undefined and I get strange results. The pis/cameras need to be headless but I should be able to check them from another network device to see status and what they're actually shooting. Right now, when I position them, it's a huge hassle because I'm positioning them after I see images show up on my laptop. And if I need to change something, I'm logging in remotely, tinkering with settings and restarting the script. The camera should do soemthing sane if it doesn't see a controling computer on the network.

I figure there has to be a better system out there already. I just haven't found it.

--
Larry Moss, http://www.airigami.com 
Airigami: The fine art of folding air.
Reply to
Larry Moss

Are you willing to share your script or give an idea of what it's about? I'm very interested in time lapses and I was doing them in early 2000s when the technology was expensive and not as good as it is today.

Are you using the raspberry pi cameras? Do you have an time lapses you can share and/or some photos from the camera? I haven't really seen many photos from the pi camera so I don't know the quality. Is it OK?

So the photos are saved on the pi SD card and periodically sent to your laptop, where they are organized by hostname or the like?

That's a nice idea. What subjects are you time lapsing where you're using three or four pis at a time?

Reply to
sean

Sure. I was hoping someone would share something better. What I have is really clunky. You probably don't want to use it. But you may be able to learn from it. I'll describe it now. I'll pull the actual script off the pi when I'm in the office.

It all revolves around raspistill. It's easy. It's already there. It even has an option to do timelapse with a single command. I don't use it that way though. I have it take one still every time it runs and have a basic loop that makes sure the networking piece is done.

I'm an installation artist. I like to capture time lapses of all of my builds. They can get quite large, so I typically set up several cameras to capture things from multiple angles and over several days, almost always in public spaces. Pis are cheap to use as cameras. RPi with camera module, case, mounting hardware, wifi (not even needed as an extra any more) come to around $75. GoPros are in the hundreds. I get a lot of functionality out of the pi that I don't get out of a GoPro, but even ignoring all of that, pis don't get stolen. And if they do, or they're smashed, all of my pics are saved across multiple machines. The quality is good, but the networking piece is the part I really care about. I have a server (usually my laptop, but could easily just be another pi - I'm just using rsync to move files) capturing everything from all cameras.

I prefer pics taken with the RPi camera over my GoPro. But I wouldn't say the pi camera is the best thing in the world. I'm still using the old pi camera. I haven't tried version 2 yet.

Here are some:

formatting link
formatting link
formatting link
formatting link

Note that almost all of the stills in the actual time lapse of those are from the pis. The stills that I'm panning over were usually shot with better cameras. The video clips are usually off of cell phones. Crew members just randomly pull out their phones and record moments during a build.

rsync just runs in the background. So files are sent asynchronously to the main machine. They also live on the local SD card until I clear them once a day. Lots of redundancy. Even having to clear them once a day is silly. The oldest files should just be wiped as space is needed. They should all be saved by that point anyway.

I'll try to remember to grab the script tomorrow.

--
Larry Moss, http://www.airigami.com 
Airigami: The fine art of folding air.
Reply to
Larry Moss

That's awesome! Both the sculptures and the time-lapse :-)

[snip]
--
Cheers, 
Chris
Reply to
Chris

Yeah, yours may not be exactly what you want, but sharing it will help give others ideas on how they could improve vs starting from nothing.

Ah, I didn't even know about raspistill. Having not owned one of the raspberry pi cameras, I didn't know the software included on it. Now that I ran it on a pi, I see it has couple dozen options. Impressive!

Yeah, I'm sure adding another pi+camera is a much easier decision over a gopro+some mounting outfit.

I didn't eve know there was a version 2! I knew there was/is a NR version that I thought about getting for about a day. How are you powering the pis? USB cable to AC or some USB battery pack?

Wow, that's some pretty impressive work! Congrats. Did you have a project like that this January? I see the pictures are all in focus and did pretty well with the white balance, although that's probably because you're inside a well lit area. Any experience outside?

Once you have all the images, you load them up on your machine and use what to put the time lapse together? Years ago, I purchased a quicktime license to something within to put my images into a time lapse. I think this was before I much about OSS/Linux.

All good pictures!

Any concerns of SD card wear? Again, SD cards are cheap and that possibility could happen with gopros as well.

Great, thanks!

An app you may like for your smartphone/tablet is called lapse it pro. Very inexpensive and many features to setup time lapses easily.

Reply to
sean

A Pi camera has a tiny aperture, it's almost a pin hole camera so depth of field is from about a few feet to infinity.

I had one showing an outside scene and time lapsed that. The white balance set to auto worked very well.

Imaging taking uses python picamera module. For processing of stills, adding date/time etc, "convert" from imagemagick and python-pil to analyse the image to determine if it's dark or not (timelapse of black stills is a bit boring) and to render the stills into a time lapse movie mencoder.

My Pi time lapse would kill a card or USB stick in about 6 weeks. But all image processing was being done on the Pi. A full HD still every

30 seconds (1920 x 1080, 1.5 MB ish, 2,880 times/day), checked to see if it's dark, if not add date/time, averge of another 1440 writes. So something of the order of 4 to 5,000 writes/pay. 8 GB card could hold about 20 days of still images and 8 timelapses on a FIFO basis.
--
Cheers 
Dave.
Reply to
Dave Liquorice

In my head, it made sense to start from scratch, so I hadn't really thought about giving anyone the version I wanted to throw out, but yeah, if others see what I'm currently doing ...

I have a few USB battery packs that I use if I need to, but I prefer to use AC power when I can. Balloons require that I build indoors (withthe occassional final assembly outside) so power is almost always available.

Thanks. We didn't do one this January. Moved into a new studio, so that took all of my time (and money).

Very little outside work at all. If you watched the space shuttle build I shared, you'll see it was assembled outside, but that piece was shot with a GoPro. Most of the places we do the mega huge builds are malls that are designed to feel big and almost always have glass ceilings. So we don't face rain and snow, but we do have the light shifting on us constantly.

I edit in Final Cut Pro. Quicktime 7 still works to load image sequences if that's all you need to do with them, but especially with multiple cameras, I need a way to edit it all together.

I've been buying fairly cheap cards and haven't had major problems. At least not during a build. I can do several installations, recording thousands of images each time before a card fails. So yeah, they do fail, but not quickly.

I'll take a look at that. One more tool to have is always good. Thanks.

My script is below. Some explanation first.

If I had an infinite amount of time, here's how it would work:

  • I could buy a new blank card, write an image to it, pop it into a pi and it would just run. There should be no need for configuration, except to fine tune what I want that day. There should be a default config that it just uses if I dont' give it anything else.
  • Since I usually use multiple camers, the first machine on should be master. This is the one that holds all the captured data. Other machine should be able to connect to that one.
  • As new cameras turn on, they'd rom a mesh network so communication just gets stronger and shouldn't need to tinker with how any of it works. Just add devices in range of others.
  • A smart phone or tablet should serve as a monitor to view where cameras are pointed and change configs on the fly.
  • Somewhere down the road, it would be awesome if cameras were mounted on servos so I could change angles on the fly from anywhere as I viewed things on my smartphone.

So here's what I'm actually doing. (Which is basically none of what I described above.) For this to work, the main server machine needs to already be running and ready to accept connections. There's no robustness built in for lost network. (Although, with rsync going, at least it will pick up where it left off if a missing machine shows up again.)

#!/bin/bash #Start RPi camera module for time lapse # Need /sbin for ifconfig. PATH="/sbin:/usr/sbin:$PATH"

# had issues with NTP, so pulling time from remote ssh. function set_time_from_server { echo getting time from $central_user typeset now if now=$(ssh "$central_user" date '+%m%d%H%M%y.%S') then echo "Old date: `date`" sudo date "$now" echo "New date: `date`" fi }

# make up a unique name for this pi. try gpio first. function get_camera_id_from_gpio { # Returns: 0 on success, non-0 on failure. typeset bit0 bit1 bit2 bit3 id bit_0=`gpio read 0` bit_1=`gpio read 1` bit_2=`gpio read 2` bit_3=`gpio read 3` id=`expr ${bit_0:-0} + ${bit_1:-0} '*' 2 + ${bit_2:-0} '*' 4 + ${bit_3:-0} '*' 8`

# If the ID isn't set up on GPIO it'll be 0. Fail. [ $id -eq 0 ] && return 1 echo "$id" return 0 }

# make up a unique name for this pi. use MAC address. function get_camera_id_from_ethernets { # Returns: 0 on success, non-0 on failure. typeset ether id mac

for ether in eth0 eth1 wlan0 wlan1 wlan2 do if ifconfig "$ether" >/dev/null 1>&2 then # It exists! mac=`ifconfig "$ether" | head -1 | awk '{print $NF}'` [ "$mac" = "" ] && continue id=`echo "$mac" | cut -d: -f4- | sed 's/://g'` [ "$id" = "" ] && continue echo "$id" return 0 fi done return 1 }

function correct_host_name { # Determine the camera ID: # Try ethernet first. Retry for a while in case it's not up yet. # If not available after a while, fall back to the hostname. typeset try for try in 1 2 3 4 5 6 7 8 9 do if id=`get_camera_id_from_ethernets` then cameraname="airigamicam$id" [ "$cameraname" = "`hostname`" ] && echo "Hostname is okay." && return 0 echo "Updating hostname to $cameraname" sudo sh -c "echo '$cameraname' >/etc/hostname" sudo hostname "$cameraname" return 0 fi sleep 5 done return 1 }

# One of the computers on the list below will be online. Just keep # trying until we find one. function locate_central_user { typeset try for try in $central_user snipped-for-privacy@beaker.local snipped-for-privacy@noah.local snipped-for-privacy@shelly.local do typeset host=$(echo "$try" | cut -d@ -f2-) if ping -c 1 $host || ping -c $host then [ "$central_user" = "$try" ] && return 0 central_user="$try" echo "Now using $central_user for central user." return 0 fi done return 1 }

# Change shot interval in a single place using central user. Shot # interval is in seconds function get_shot_interval { echo getting shot interval from $central_user shot_interval=$(ssh "$central_user" cat shot_interval) return 0 }

status=`ps -e | grep -v grep | grep raspistill` if [ ! -z "$status" ] ;then echo raspistill is already running exit fi

central_user=" snipped-for-privacy@beaker.local" echo double checking central_user: $central_user locate_central_user set_time_from_server correct_host_name shot_interval=30 get_shot_interval echo shot_interval is $shot_interval

start=`date "+%Y%m%d%H%M%S"` # folder name from start time of script

cameraname="`hostname`" central_dir="timelapses/$cameraname" rootdir="/home/pi/timelapse-$cameraname" folder="$rootdir/$start" #duration="999999999" # Will run for 1.5 days #freq="20" # Shot frequency: every minute

mkdir -p "$folder" # take pics suitable for 720p video (1280x720). Rotate so pi can sit flat. # raspistill -n -rot 90 -t $duration -tl $freq -h 720 -w 1280 -o "$folder/timelapse_\%d.jpg" & #raspistill -n -rot 90 -t $duration -tl $freq -o "$folder/timelapse_\%d.jpg"

# Repeat indefinitely: while true do # Snap once per minute. # Doing it this way instead of simply 'sleep 60' prevents skewing over time. sec=`date '+%S'` # sleep `expr 61 - $sec` # sleep $shot_interval sleep $(expr $shot_interval - $sec % $shot_interval)

# Take the snap imagename="timelapse_`date '+%Y%m%d%H%M%S'`_$cameraname.jpg" raspistill -n -rot 90 -h 1080 -w 1920 -o "$folder/$imagename"

# Check to see if rsync is running. # if it's not, start one. if ! killall -0 rsync >/dev/null 2>&1 then locate_central_user && rsync -a "$rootdir" "$central_user:" & fi done

--
Larry Moss, http://www.airigami.com 
Airigami: The fine art of folding air.
Reply to
Larry Moss

Here is my script for a webcam. Saves to RAM, uploads to server. I commented out saving to /tmp because it turned out looking at the timelapse video (separate crontab 'makevideo' script every night) was only fun for a couple of times. It used filenames ending in minutes, so only one pic per minute left, others overwritten.

Other scripts used:

formatting link
formatting link
formatting link

#!/usr/bin/env bash

TWILIGHT=30

MEM='/run/shm/cam.jpg' SRV=' snipped-for-privacy@example.com' DIR='public_html/picam/' ID='/home/pi/.ssh/id_rsa'

PREV=2500 while true; do

CLOCK=$(date +'%-H%M' | sed -r 's/^0*([0-9])/\1/') if (( CLOCK < PREV )); then # New day set $(sun) DAWN=$(timedelta $1 -$TWILIGHT) DUSK=$(timedelta $2 +$TWILIGHT) fi PREV=$CLOCK

# Take picture if (( CLOCK >= DAWN && CLOCK

Reply to
A. Dumas

Thanks for the script and links to others. Do you have any time lapses you can share?

Reply to
sean

Thanks for sharing! I'm going to check into the raspberry pi cameras. I didn't even consider needing to have the time synced for multiple cameras. Good thinking

Right, I had assumed it was a mall or the like where you have good AC power.

Best of luck at your new studio. Keep the time lapses going!

That's better than I was expecting, good to know.

What I used years ago was was one of these:

formatting link

I don't recall the exact model, I think it may have been something in between the 2100 and 2700.

It was connected to a Nikon Coolpix. Back then, CF cards were expensive and the pictures were not as sharp as they are with yours. I did have the advantage of the camera having its own power supply, although it doesn't seem too difficult to power the pi.

Do you think you'll work on any of those above, or are you feeling okay with it now?

Reply to
sean

Do you se the white balance with the python picamera module? Is that the same thing Larry referenced earlier?

Just curious, are you processing the stills on the pi or copying them over to x86?

Do you have any you're willing to share?

If you're doing a time-lapse outside, do you set a time frame of when it doesn't need to snap pictures?

Ah, so you're using imagemagick on the raspberry pi? Wow, that's quite a long time-lapse. Since it sounds like you're doing these outside, how are you powering the pi? Do you use the raspberry pi camera version 1 or 2?

Reply to
sean

Only the daytime:

formatting link
Windy day and changing cloud cover = lots of movement = fairly large file size at 20 MB. Also the cam is pointed badly for winter: half sky with low sun, half ground in the dark = difficult dynamic range for a tiny sensor that isn't exactly HDR.

Reply to
A. Dumas

I had two scripts. One python to take the still image every 30 seconds, look at the average level and throw it away if it was below a set threshold (ie it's dark). If it was above the threshold it used imagemagick to add a semi transparent box that contained the date/time. This script started on boot up.

The second script was a bash one, called by a cron, to render the time lapse via mencoder and I think to manage the FIFO file handling.

Mine was all done on the Pi (a Pi 2) that also had nginx installed so I could simply see the results on the LAN via a browser.

There is a slight "technical problem" with that. It's a while ago since I took the camera down as it was eating cards and sticks. I still have them but the user (and root) passwords illude me ATM. I'm letting my subconcious mind work on that...

I did think about that but the time of darkness varies by time of year and the weather. Decided that taking a mean level of the image would be better and automatic. It actually worked very well evening would fade down to black then fade back up with the next morning. Bear in mind the location is rural and when it goes dark it goes DARK. It might not work so well if there is much artifical light about.

I'd generate one every 6 hours (taking several hours to render). Compressing 6 hours into just under 2 minutes. I played with the hardware rendering capabilties of the Pi, very fast, minutes if not seconds but very poor quality.

Pi and camera inside looking out of a window. Pi camera lens right up to the glass looking through a hole in some black plastic sheet, more sheet covered camera to eliminate reflections. "Black plastic sheet" being sourced from some chilled food packaging.

It has "Rev 1.3" printed on it.

--
Cheers 
Dave.
Reply to
Dave Liquorice

Blimey. I thought they were there to protect you, not do magic tricks with your cash dispenser....

By the way, that should be 'MY' ATM.

:-0

--
"The great thing about Glasgow is that if there's a nuclear attack it'll  
look exactly the same afterwards." 

Billy Connolly
Reply to
The Natural Philosopher

Dana Sun, 05 Feb 2017 02:28:05 +0000 (GMT), Dave Liquorice napis'o:

Just plug the SD card into reader and mount it on another linux machine. Remove password for root from /mountpoint/etc/passwd or /mountpoint/etc/shadow

And after loging on... change it with passwd command.

Reply to
Nikolaj Lazic

Eats, shoots and leaves?

--
Cheers 
Dave.
Reply to
Dave Liquorice

Managed to get access to the card that was used as combined OS and image store before in went into "safe, read only" mode.

formatting link

This is from before the average level checking so it's the whole 0000 to 2359 day squeezed into 1'55". It starts and ends with several seconds of black... Uplink speed may prevent streaming probaby best to download it's about 36 Meg.

The USB stick used as an image store seems well dead, log messages indiacte no valid filesystem can be found...

--
Cheers 
Dave.
Reply to
Dave Liquorice

Fabulous sky! Have you any idea what the windspeed was? Its difficult to tell how strong the wind was with the timelapse, but the cloud development makes it look like a very interesting soaring day indeed.

--
martin@   | Martin Gregorie 
gregorie. | Essex, UK 
org       |
Reply to
Martin Gregorie

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.