Vagrearg Logo  
 
Banana g(r)o(w)ing bananas
Time lapse experiment
Having fun with a very old webcam and a banana plant. Yes, it is a miracle, both the banana plant and the webcam.

Taking one picture every hour using a raspberry pi, hacked together lighting and very old webcam. Doesn't matter, it works and is fantastic. Nature still makes the most fascinating and wonderful imagery.
Banana growing with images taken at 1 hour interval. This video should update on the server automatically every hour. Reload the page to view the update.
Images start on 2022-11-17. The first week is missing night images. The light added on the 23rd of November for 24 hour coverage. And, yes, the plant also grows during the night.
The system is kept very simple. A RPi on the local WiFi has a cron script running to capture an image every hour. The script also controls a 12V light via GPIO. Everything is cobbled together from what was found in the drawers, kitchen and garage. A lovely hack project :-)
banana-setup
The setup with camera and light.
banana-control
Raspberry Pi connected via WiFi.
banana-light-switch
Lighting control switch... One whole wonderfully ancient metal-can NPN transistor. Absolute magic at work.
Small update: The plant is approximately growing at a rate of 125μm per hour (3mm per day). At the 11th of December 2022 it had grown out of the top of the image. The camera was adjusted and recordings continue. The plant will again grow out of the top soon. I will probably stop the recordings when that happens. Maybe I can find another target ;-)

Final update: the plant is too big and the rig too inflexible to continue.
banana-final
The final size when I quit recording (01-Jan-2023). The plant's growth was mainly out of the field of vision and the rig was not flexible enough to keep everything in view.

The code to take an image:
#!/bin/bash

unset DISPLAY

MYDIR="/tmp/imgs"
mkdir -p $MYDIR
cd $MYDIR

# Make sure we have GPIO 4 exported
[ -d /sys/class/gpio/gpio4 ] || sudo echo "4" > /sys/class/gpio/export
sleep 0.5

# Turn on the light
if [ -d /sys/class/gpio/gpio4 ]; then
	sudo echo "out" > /sys/class/gpio/gpio4/direction
	sudo echo "1" > /sys/class/gpio/gpio4/value
	sleep 1
fi

# The extra shell is to kill the SIGSEGV message from the shell because guvcview crashes on exit
bash -c "guvcview -i $MYDIR/banana.jpg -g none -m none -n 1 -t 1 -e > /dev/null 2>&1" 2> /dev/null

# Turn off the light
if [ -d /sys/class/gpio/gpio4 ]; then
	sudo echo "0" > /sys/class/gpio/gpio4/value
fi

# Save data to remote server
if [ -f "$MYDIR/banana-1.jpg" ]; then
	scp "$MYDIR/banana-1.jpg" "user@server.example.com:bananas/banana-$(date "+%Y%m%d%H%M%S").jpg" > /dev/null 2>&1
fi

cd /tmp
rm -f $MYDIR/*
And converting it to a movie:
#!/bin/bash

# The script directory contains all images. Make sure we are there
cd $(dirname "$0")

# Annotate the image(s) with date/time stamp
for i in banana-*.jpg
do
	# file must exist (it doesn't if glob failed)
	[ -f "$i" ] || continue
	mv $i tmp.jpg
	# Extract date/time from filename
	TXT="$(echo "$i" | cut -c 8-15) $(echo "$i" | cut -c 16-19)"
	convert tmp.jpg \
		-font DejaVu-Sans -pointsize 20 \
		-fill black \
		-stroke black \
		-strokewidth 2 \
		-annotate +20+25 "$TXT" \
		-stroke None \
		-fill white \
		-annotate +20+25 "$TXT" \
		"a${i}"
	rm -f tmp.jpg
done

# Video ahead, one image at a time
ffmpeg -loglevel error -y -framerate 24 -pattern_type glob -i 'abanana-*.jpg' -c:v libx264 -pix_fmt yuv420p zzbanana.mp4
# Covert it to webm too
ffmpeg -loglevel error -y -i zzbanana.mp4 -cpu-used -5 -b:v 0 -crf 30 -pass 1 -an -f webm /dev/null
ffmpeg -loglevel error -y -i zzbanana.mp4 -cpu-used -5 -b:v 0 -crf 30 -pass 2 zzbanana.webm
rm -f ffmpeg2pass-0.log

# Make accesible by webserver
mv -f zzbanana.mp4 /my-web-directory-somewhere-in-space-and-time/banana.mp4
mv -f zzbanana.webm /my-web-directory-somewhere-in-space-and-time/banana.webm
Note: Make sure you understand the scripts if you copy these scripts. You need the right directories setup across multiple machines.

Posted: 2022-12-03
Updated: 2023-01-01

 
 
Overengineering @ request