Thursday, January 1, 2015

69: To Catch a Thief
(Raspberry Pi Security System)

My daughter's dog is an inveterate thief of any food left within even implausible reach. The previous time we dog-sat for him he managed to steal over a dozen home-made cookies. So I decided to catch him in the act using my Pi+camera+Python program. I have a (fairly) portable Pi system:
Notes on the configuration:
  • The 12,000mAh battery will power the Pi for about 10 hours. Unfortunately the battery can either charge or discharge but not both at once. Otherwise it would make a very nice UPS (uninterruptable power supply).
  • As shown, it has LED output, PIR and Pi camera input and a 7-segment display. On the side there is a Cat5 socket (provides 8 wires for remote sensors) and a pair of relay switches.
  • I use the speaker for text-to-speech output.
Anyway, I baited the kitchen counter with a piece of meat and set the porta-Pi aimed at the counter. On my first attempt my program just used the camera to detect motion. About once per second the Pi can take a grayscale 120x90 pixel image which the program compares pixel-by-pixel with the previous image. When more than an arbitrary number if pixels have changed by more than an arbitrary difference then the program takes a full-res image and saves it to the SD card filesystem.

This first test failed for 2 reasons: a) the dog ignored the bait; b) while we were away for about 3 hours the sun went under a cloud and back out about 100 times and my dumb program decided that each such change was "motion."

So, for my second try I added the PIR device -- logic as follows:

    IF the PIR detects motion AND the 2 camera images differ THEN store the high-res image.

This attempt failed too: at  a distance of about 12' the PIR didn't notice the 30-pound white dog (but he stole the meat).

I need a better motion detector.

No comments:

Post a Comment