User avatar
Mettauk
Posts: 235
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Embedding Date and Time in Timelapse

Sun Apr 27, 2014 5:33 am

I found a small script to capture stills from Andrew Beck

ROLL=$(cat /var/tlcam/series)
SAVEDIR=/var/tlcam/stills
while [ true ]; do
filename=$ROLL-$(date -u +"%d%m%Y_%H%M-%S").jpg
/opt/vc/bin/raspistill -o $SAVEDIR/$filename
sleep 4;
done;


I want to embed the time in within each captured frame (botom left if poss). can anyone help.

This may have been dealt with but I could not find it in the forum.
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
DougieLawson
Posts: 35784
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Embedding Date and Time in Timelapse

Sun Apr 27, 2014 7:51 am

Change

/opt/vc/bin/raspistill -o $SAVEDIR/$filename

to
raspistill -x -o $SAVEDIR/$filename

adding the -x flag gets EXIF data written to the image, the EXIF data includes the date and time.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
Mettauk
Posts: 235
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: Embedding Date and Time in Timelapse

Sun Apr 27, 2014 8:00 am

Thanks but I want to see the date and time in the image (Pref bottom left) not just in the jpg file data or am i missing something with -x ?

I found imagemagick and can post convert but with thousends of captured images it makes sence to do that at the time of image capture.

#!/bin/bash

for file in *.jpg ; do
convert "$file" -font arial \
-pointsize 72 -fill white -annotate +100+1850 \
%[exif:DateTimeOriginal] "new-${file}"
done
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
DougieLawson
Posts: 35784
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Embedding Date and Time in Timelapse

Sun Apr 27, 2014 8:04 am

Just by running raspistill with -x I get

Code: Select all

Camera Maker: RaspberryPi
Camera Model: RP_OV5647
Image Date: 2014-04-14 11:27:02 (no TZ)
Color Space: sRGB
GPS Coordinate: undefined, undefined
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7124
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Embedding Date and Time in Timelapse

Sun Apr 27, 2014 8:06 am

Currently there is no way to do this on the GPU (and all the encoding is done there with no extra requirement on the ARM)
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
Mettauk
Posts: 235
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: Embedding Date and Time in Timelapse

Sun Apr 27, 2014 8:18 am

6by9 wrote:Currently there is no way to do this on the GPU (and all the encoding is done there with no extra requirement on the ARM)
Oh... thanks. :?
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Embedding Date and Time in Timelapse

Tue Apr 29, 2014 4:01 pm

You can avoid losing detail to jpeg compression TWICE by getting raspistill to output a lossless format like BMP,
then only using jpeg after adding the datetime to the image:

Code: Select all

raspistill  -n -t 500 -e bmp -o - | convert -pointsize 72 -annotate +30+100 "$(date)" - image.jpg
That does take around 4 seconds to run on a full 2592x1944 frame though !
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
Mettauk
Posts: 235
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: Embedding Date and Time in Timelapse

Tue Apr 29, 2014 8:24 pm

Thanks I have tried

Code: Select all

raspistill -w 1280 -h 720 -x -n -e bmp -o - | convert -pointsize 24 -fill white -annotate +30+680 "F1 $(date)" - 
It takes around 7-8 seconds between images on medium overclock 256 Pi.

I would like to reduce it down to the 4 seconds or less. Any ideas?
The full code being used is

Code: Select all

ROLL=$(cat /var/tlcam/stillsa)

SAVEDIR=/var/tlcam/stills

while [ true ]; do
filename=$ROLL_$(date -u +"%d%m%Y_%H%M-%S").jpg
/opt/vc/bin/raspistill -w 1280 -h 720 -x -n -e bmp -o - | convert -pointsize 24 -fill white -annotate +30+680 "F1 $(date)" - $SAVEDIR/$filename 

sleep 0;

done;
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

ethanol100
Posts: 583
Joined: Wed Oct 02, 2013 12:28 pm

Re: Embedding Date and Time in Timelapse

Wed Apr 30, 2014 9:53 am

Do you finally need jpeg images?

If you just want to look at the annotated images you could create svg images.
The svg image is just a text file which contains a link to the jpeg and a text element.
Creating these svg images is fast and easy. You can i.e. create a template using inkscape and later copy the template and replace the link to the jpeg file and the text only.

So what do you exactly want to do with this pictures? Create a video? Use as security system?

You can not really speed up the process, if you want to annotate the images using jpegs. Saving a full frame image to bmp will take several seconds, because the "encoding" is done on the cpu and more data needs to be copied to the arm side. And imagemagick uses only the cpu to create the final jpg. Only way to speed this up is using a smaller image size(i.e. 640x480 px).

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Embedding Date and Time in Timelapse

Wed Apr 30, 2014 10:33 am

Yes, CPU= slow, GPU = fast

I was having a play with tasanakorn's mmal code this morning to overlay text onto video using GPU
and save the result:

https://github.com/mikerr/rpi-mmal-demo

if you just want the binary:

Code: Select all

wget https://www.dropbox.com/s/rboi6nangraccbn/vid_overlay
chmod a+x vid_overlay

Code: Select all

./vid_overlay -t 2 -s "$(date)"  > test.h264 
omxplayer test.h264
-t is the duration of clip in seconds
-s is the overlay string

Stills should be similar, I'll look later.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7124
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Embedding Date and Time in Timelapse

Wed Apr 30, 2014 2:26 pm

That code on mikerr's github should be usable as a basis for JPEG encode too.

For video encode the GPU will be doing a few more conversions/copies but otherwise should be fine.
On stills you will lose EXIF and thumbnail as the metadata required only gets passed on MMAL_ENCODING_OPAQUE buffers. Stick with MMAL_ENCODING_I420 if you want to avoid extra conversions. You'll also have a couple of very large buffers being passed around (5MPix I420 = 7.5MB), so memory may become a little tight under some situations.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Embedding Date and Time in Timelapse

Wed May 07, 2014 2:02 pm

Forgot to update this with the stills version..

Code: Select all

wget https://www.dropbox.com/s/ydxz55y0nt9b8q4/still_overlay
chmod a+x still_overlay

Code: Select all

./still_overlay -s "$(date)"  > test.jpg 
Mettauk wrote: It takes around 7-8 seconds between images on medium overclock 256 Pi.

I would like to reduce it down to the 4 seconds or less. Any ideas?
The above now runs in 0.5 sec including capture :lol:
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
rleyden
Posts: 70
Joined: Thu Jun 14, 2012 2:17 am

Re: Embedding Date and Time in Timelapse

Wed May 07, 2014 5:02 pm

mikerr wrote:Forgot to update this with the stills version..
The above now runs in 0.5 sec including capture :lol:
Very nice, thanks.
How hard would it be to include rotation and exposure into still_overlay?

I have a Pi Noir setup to capture wildlife at night. I get great exposures with a near-IR diode light source and using "-ex night" and raspistill. The captures take more than a second but that's OK. Using raspivid gave me unpredictable results. I have a PIR sensor that I can use to trigger the camera. But, given the slow capture rate, it was be better to just capture continuously. I use mencoder to string the frames together so I can quickly review it for wildlife. Including a timestamp on the frame makes it easier to go back and find the frames of most interest. Right now, running flat out, I manage 4 frames a minute. Faster would increase the odds of getting an interesting shot.

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Embedding Date and Time in Timelapse

Wed May 07, 2014 5:25 pm

rleyden wrote:
mikerr wrote:Forgot to update this with the stills version..
The above now runs in 0.5 sec including capture :lol:
Very nice, thanks.
How hard would it be to include rotation and exposure into still_overlay?
Not too hard, but better would be to move the overlay code into raspistill, so you get all the options available.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
Mettauk
Posts: 235
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: Embedding Date and Time in Timelapse

Wed May 07, 2014 6:39 pm

Code: Select all

wget https://www.dropbox.com/s/ydxz55y0nt9b8q4/still_overlay
chmod a+x still_overlay

Code: Select all

./still_overlay -s "$(date)"  > test.jpg 
Thanks for this but I'm not sure how to incorperate this code into the stills capture I have been using?

Code: Select all

ROLL=$(cat /var/tlcam/stillsa)
SAVEDIR=/var/tlcam/stills
while [ true ]; do
filename=$ROLL_$(date -u +"%d%m%Y_%H%M-%S").jpg
/opt/vc/bin/raspistill -w 1280 -h 720 -x -n -e bmp -o - | convert -pointsize 24 -fill white -annotate +30+680 "F1 $(date)" - $SAVEDIR/$filename 
sleep 0;
done;
Which as said before take 7-8 seconds between images. So getting this down seems ideal.
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
algorithm
Posts: 181
Joined: Mon Nov 25, 2013 9:09 pm
Location: Flatland

Re: Embedding Date and Time in Timelapse

Wed May 07, 2014 8:26 pm

PHP on a web server on the Pi can easily keep up with raspistill time lapse shots every 2 seconds (which is better than re-starting raspistill every x seconds) for 800x600 jpegs in memory. See http://dronkert.net/rpi/webcam.html

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Embedding Date and Time in Timelapse

Wed May 07, 2014 11:47 pm

Mettauk wrote: Thanks for this but I'm not sure how to incorporate this code into the stills capture I have been using?
Your new script would be something like:

Code: Select all

ROLL=$(cat /var/tlcam/stillsa)
SAVEDIR=/var/tlcam/stills
while [ true ]; do
filename=$ROLL_$(date -u +"%d%m%Y_%H%M-%S").jpg
/home/pi/still_overlay -t 3 -s "F1 $(date)"  > $SAVEDIR/$filename 
sleep 0;
done;
I ran that and got 60 timestamped images in 60 seconds:

Image
Android app - Raspi Card Imager - download and image SD cards - No PC required !

stephanl
Posts: 3
Joined: Tue Aug 23, 2016 1:33 pm

Re: Embedding Date and Time in Timelapse

Tue Aug 23, 2016 1:44 pm

Hello Mike,
I was trying to compile your source of the code you modified for still capture with text overlay.
I did it on a model 2 b+ with an up to date patched version of jessie. When issuing the make command
the following errors stopped make from continuing:

pi@raspberrypi:~/src/raspberrypi/build/rpi-mmal-demo $ make
Scanning dependencies of target mmal_buffer_demo
[ 20%] Building C object CMakeFiles/mmal_buffer_demo.dir/buffer_demo.c.o
Linking C executable mmal_buffer_demo
[ 20%] Built target mmal_buffer_demo
Scanning dependencies of target mmal_opencv_demo
[ 40%] Building C object CMakeFiles/mmal_opencv_demo.dir/opencv_demo.c.o
Linking C executable mmal_opencv_demo
/usr/bin/ld: CMakeFiles/mmal_opencv_demo.dir/opencv_demo.c.o: undefined reference to symbol 'sem_post@@GLIBC_2.4'
//lib/arm-linux-gnueabihf/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/mmal_opencv_demo.dir/build.make:114: recipe for target 'mmal_opencv_demo' failed
make[2]: *** [mmal_opencv_demo] Error 1
CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/mmal_opencv_demo.dir/all' failed
make[1]: *** [CMakeFiles/mmal_opencv_demo.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2

Could you please hint me in the right direction how solve this?
Any help much appreaciated.

Regards

Stephan

stephanl
Posts: 3
Joined: Tue Aug 23, 2016 1:33 pm

Re: Embedding Date and Time in Timelapse

Mon Sep 12, 2016 9:44 am

I did get the code compiled by adding the missing links to the corresponding executables in the CMakelist.txt.
That was not so difficult. But when still_overlay is executed the time stamp does not appear on every jpg. I am not sure why that is. Could it be that the rasclock module is interfering? My guess would be No. I tried it on jessie as well on wheezy. On wheezy I got one jpg with time stamp :D

I upped the GPUs memory with no difference.
The file names though are with the corresponding time stamp with a two hour difference.
I will try to remove fake-hwclock and see if that makes difference.

I also was wondering which bit in still_overlay writes the time stamp overlay onto the jpg?
Where would I add that to raspistill?

Any help much appreciated

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Embedding Date and Time in Timelapse

Mon Sep 12, 2016 8:43 pm

My code above was written before raspistill had annotation built in, nowadays you can do:

show date and timestamped image:

Code: Select all

raspistill --annotate 12 -o test.jpg
https://www.raspberrypi.org/documentati ... /camera.md
Android app - Raspi Card Imager - download and image SD cards - No PC required !

stephanl
Posts: 3
Joined: Tue Aug 23, 2016 1:33 pm

Re: Embedding Date and Time in Timelapse

Tue Sep 13, 2016 9:22 am

That decomplicates things.

Thx

Return to “Camera board”