Tonight I got hold of a web cam for the first time in my life. I was stuck for something to do with it, so I thought I would try and turn it into a motion sensor.
UPDATE: An example of this idea catching a thief. Made me realise I need to store my photos off-site. Silly mistake.
UPDATE: An example of this idea catching a thief. Made me realise I need to store my photos off-site. Silly mistake.
First I remembered seeing a reference to a motion sensor package on PacketStorm, which I found. It is called Motion. It gave me some trouble compiling the ffmpeg components, eventually I just set --without-ffmpeg. The JPG's are more than adequate.
Next I got hold of the new Philips Web Cam driver for my camera. As I already had bttv compiled and ready I just compiled this as an external driver, put it in /lib/modules/`uname -r`/kernel/drivers/usb/media/pwc.ko, depmod'ed and it registered as a video4linux device.
I first tested it with mplayer and the following command line:
mplayer tv:// -tv driver=v4l:device=/dev/video1:width=640:height=480
It required some focus and placement.
Next up I got motion working nicely and wanted it to mail me and lock my machine. I wrote a quick script to do so:
#!/bin/bash
sleep 5
~/bin/motion -t ~/pics/shots -d /dev/video1 \
-B -E "~/bin/motionmail" \
>> ~/pics/shots/spy.log&
/usr/bin/xtrlock
killall motion
sleep 5
~/bin/motion -t ~/pics/shots -d /dev/video1 \
-B -E "~/bin/motionmail" \
>> ~/pics/shots/spy.log&
/usr/bin/xtrlock
killall motion
The sleep is to give me time to get out of my room.
motionmail contained:
#!/bin/bash
temp=`mktemp -q /tmp/motion.XXXXXX`
echo 'Motion was detected in your room at:' > $temp
echo >> $temp
date >> $temp
mail -s "Motion Detected" singe < $temp
rm $temp
temp=`mktemp -q /tmp/motion.XXXXXX`
echo 'Motion was detected in your room at:' > $temp
echo >> $temp
date >> $temp
mail -s "Motion Detected" singe < $temp
rm $temp
This all took me about 45 minutes to do and then about 30 minutes of playing with camera angles and detection thresholds. Motion is clever and only sends one mail per motion event but generates hundreds of JPG's. A bit of fun for an evening with some potential serious security benefits if done properly.
UPDATE: Improved the scripts.
Trackbacks
Trackback specific URI for this entry
No Trackbacks

