Friday 24 August 2018

Intelligent motion detection camera

So what Have I been doing with all this object detection? Simple, setting up a security camera!

It's quite simple, I started an age ago with building a camera from a pi-zero with a pi-cam (with the ir filter removed). Just find a dummy housing, like this one:

The install motion-eye (The instructions there are awesome) and you've got a security camera!

Next, wouldn't it be nice to alert you when it found something.. So I tried setting up motion-eye to trigger when it thought it saw something, but it was always giving me lots of false positives, for example when a cloud went overhead, a lot of pixels would change, then it would alert me.

Hmm not ideal, I wasn't that keen on having a cloud alerting function.

That's why I wrote the web service that you can find here on GitHub. So I set it up to email me when it detects. Even with that, I still got a lot of false object detections, so I modified the web service to have a filter and only filter if it spots one of the defined labels (- car     - person     - bicycle     - motorcycle     - cat     - dog)

How?
Well setup motion-pi like so:


download the source code from git
git clone https://github.com/stevegal/objectdetect_ws.git
cd objectdetect_ws

modify the application properties for your setup (in src/main/rescources) and build it and run it
mvn clean package
java -jar target/objectdetect4j-0.1-SNAPSHOT.jar

and now the detect script should look like:
#!/bin/bash

cd 
WORKING_DIR=$(ls -t | head -1)

cd $WORKING_DIR

for filename in *.jpg
do
 curl -m 5 -F "image=@$filename" http://:/detect/mailTo?mailTo=
 rm -f $filename
done

You now should have a security camera that sends you an email if it spots any of the objected you setup in the spring properties file. The email should look like this


with a nice box around the things it has spotted. Works for me!