User avatar
Posts: 3476
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

'motion' thumbnails showing movement area only

Thu Aug 15, 2013 5:54 am

I wanted motion to generate not only a still with the full field of view whenever motion was detected, but also a thumbnail showing just the "area of interest" where motion had occurred (as I mentioned here). This makes it easier to view a large number of events at once, as a thumbnail index. I got this to work with dozencrows' version of mmal-motion (but I think this is generic syntax) with the adjustments below.

The edited mmal.conf configuration file fragment was changed as follows:

Code: Select all

# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
# To give the filename as an argument to a command append it with %f
; on_picture_save value
on_picture_save /home/pi/mmal/ %f %i %J %K %L
The bash script file which actually generates the area-of-interest thumbnail is below, using ImageMagick 'convert' to do the heavy lifting.On my system my full images are in /home/pi/mvideo/, and my thumbnails are in the /home/pi/mvideo/thumbs/ subdirectory. I had to do some math in the shell script because 'convert' wants the corner coordinates for the crop operation, but motion gives the center coordinates instead. Then there are the brackets to strip the first part of the full pathname, so I can replace that with the path including the subdirectory name.

Code: Select all

XT=`expr $2 / 2`
XO=`expr $4 - $XT`
YT=`expr $3 / 2`
YO=`expr $5 - $YT`
convert $1 -crop $2x$3+$XO+$YO -resize 200x200 /home/pi/mvideo/thumbs/${1#/home/pi/mvideo/}
I use a .php file on the server to generate the index with clickable links to the full version, a simplified version of the one shown here.

Return to “Camera board”