OpenCV is an open-source framework for computer vision. It’s used for self-driving cars, surveillance, CCTV, traffic flow measurement, autonomous robots, license plate recognition, gesture recognition, and just about any other application where a computer needs to “see”.
You’ll have seen OpenCV in action whenever you’ve watched a surveillance scene in a film or documentary showing boxes being automatically drawn around moving people or cars on a computer screen.
OpenCV 3.3.0 runs well on a Raspberry Pi 3 using either the Pi camera module, USB webcam or USB video grabber and CCTV camera. Our examples run in Python 3. We have different code examples for the Pi camera and USB webcam/video grabber.
Here’s face recognition running on a Raspberry Pi 3 with the Raspberry Pi NoIR camera module
And here’s my CCTV system hooked up to the Raspberry Pi using a USB video grabber
This script looks for movement in the right of the image and saves time and date stamped photos of intruders to the Raspberry Pi’s micro SD card.
It would be quite easy to have it email the photo to you also.
There’s a full PDF guide with download links for our Python scripts here: https://www.securipi.co.uk/OpenCV.pdf
Here’s what each script does:
test-video-picam.py – shows a live feed from the Pi camera on your Desktop
find-faces-picam.py – displays a box around any face found in the Pi camera feed
find-faces-picam2.py – as above but records time stamped photos to SD card too.
mog-picam-1.py – Uses Mog2 background subtractor, takes a photo of large items on the left.
mog-picam-2-.py – as above but with erosion and dilation filters too.
Also similar examples for USB webcam or USB video grabber, without the picam titles:
test-video.py – shows live vide feed from USB webcam or USB video grabber.
find-faces.py – finds faces in the video feed and draws a box around them.
mog.py – Uses Mog2 background subtractor to find intruders and cars on our CCTV camera.
By comparing test-video-picam.py and test-video.py you can see exactly how to modify other OpenCV Python scripts for use with Raspberry Pi camera or USB webcam.
You can buy the OpenCV3 compatible USB video grabber we used, that will let you attach any video device with a composite output to your Pi, here: