Picture Server Storing Millions of jpg's!
Jerry McBride
mcbrides9 at comcast.net
Thu Jan 3 05:27:58 PST 2008
On Wednesday 02 January 2008 05:02:20 pm Shawn wrote:
> Hi guys,
>
> I have a system of IP camera's that are supposed to FTP snapshots upon
> motion sensing at a number of remote sites. The cameras seem to send
> far more pictures even when things are static and I've ended up with
> litterally millions of 10-20K jpg's, not all of which I need to save as
> it were.
>
----snip----
As I understand it, you want to be able to weed through a pile of pictures and
sort out only the interesting bits?
Here's a piece of bash that I used to "take pictures" via a webcam. When
motion was detected between any two snapshots. a date branded copy of the
last picture was put into a holding directory for later use. I have no
recollection where I got this from... Hell, I may even be the author... :')
What it does is... snaps a picture, quantifies it, snaps another picture,
quantifies it too, compares last to first, if theres a substantial difference
between the two pictures then save the last picture for later viewing...
otherwise just loop while updating the first image with the second one... go
do it again.
Worked great. I only got snapshots in the save directory when something
actually moved in the watched area. I used this for years to monitor the
hallway that lead to the IT offices where I worked. Uhm... for various
reasons. :')
Since this is bash, it is easily hacked to fit your needs... by having it
weed/loop through the pictures in your holding directory and saving the ones
of substantial difference to a different directory. I'll leave the necessary
hacking to you.
Good luck and have fun.
Caution: Indentation has been compressed out to try to eliminate word wrap.
#!/bin/bash
#
#Uses tools from media-video/w3cam, media-libs/jpeg and media-libs/netpbm
#
#RESOLUTION=320x240
DEVICE=/dev/video0
#FRATE=1
SENSITIVITY=35
echo "Setting up"
mkdir /motion
mkdir /motion/pics
cd /motion
# cleanup
rm /motion/image.jpg
# take a snapshop
vidcat -q 100 -d $DEVICE -f jpeg -o /motion/image.jpg
#cleanup
rm /motion/image.ppm
#decompress image
djpeg -scale 1/4 -pnm /motion/image.jpg > /motion/image.ppm
#one big endless loop...
while true
do
echo "Taking a picture"
#cleanup
rm /motion/image2.jpg
#take a snapshot
vidcat -q 100 -d $DEVICE -f jpeg -o /motion/image2.jpg
#cleanup
rm /motion/image2.ppm
#decompress image2
djpeg -scale 1/4 -pnm /motion/image2.jpg > /motion/image2.ppm
#get the current date and time
date>/Ycolour
#compare the signal-to-noise ratio of the two uncompressed images
pnmpsnr /motion/image.ppm /motion/image2.ppm >> /Ycolour 2>&1
#snip out the data that what we want
Y=`awk '/Y color component/ {print int($5)}' /Ycolour`
#show it
echo $Y
#if there's sufficient difference then brand and save image2
if [ $Y -lt $SENSITIVITY ]
then
cp /motion/image2.jpg /motion/pics/`date +%m%d%H%M%S.jpg`
echo "Motion detected"
fi
#use uncompressed image2 for base of next comparison
mv /motion/image2.ppm /motion/image.ppm
#do it again
done
#we will never reach this exit...
exit
--
>From the Desk of: Jerome D. McBride
More information about the Linux-users
mailing list