I wanted to get a good smart camera a while ago but the requirements I had did not justify the cost associated with it. So, I decided to create one from the parts I already had.Required parts:Raspberry PI 3A WebCamPIR sensor / Ultrasonic SensorRequired Knowledge:PythonOpenCVdlibIf you want more information regarding OpenCV and dlib then please take a look at my old article.
What is PIR sensor?A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors.
All objects with a temperature above absolute zero emit heat energy in the form of radiation. Usually this radiation isnt visible to the human eye because it radiates at infrared wavelengths, but it can be detected by PIR sensor.What is an Ultrasonic Sensor?
An ultrasonic sensor is an instrument that measures the distance to an object using ultrasonic sound waves. Ultrasonic sound vibrates at a frequency above the range of human hearing. it uses a single transducer to send a pulse and to receive the echo.
The sensor determines the distance to a target by measuring time lapses between the sending and receiving of the ultrasonic pulse.ApproachIn laymans term, the PIR sensor will detect moments and the camera will capture frames where Raspberry PI will perform facial recognition and provide final output. In more details, I have connected PIR sensor with Raspberry PI and WebCam is facing the front door of my apartment.
I am not using AWS or any other cloud services to perform inference or sending notifications. I am doing local inference and playing sounds on my speaker regarding who entered. Raspberry PI alone is not an ideal embedded platform for performing live/real-time inference till now.
So, I am using PIR sensor to find out when to start inference engine and perform face recognition. You can also use Ultrasonic distance measurer but in my case I am going to use it for another project of mine. PIR sensor will start detecting as soon as the door is opened and a person starts entering in.
The moment PIR sensor detects any kind of movements, the Camera will start capturing frames for 10 seconds. At the same time OpenCVs Haar Cascades will start detecting faces and dlibs 68 point face landmark detection will match detected faces landmarks with saved ones to check whether its an intruder or not?Using OpenCV, we can capture frames from the WebCam and convert each frame into numpy array.
Here, we are recording frames at the rate of 320x240. We can also record full HD frames but performing face detection will take lot of time on Raspberry PI. Then after using haarcascade_frontalface_alt2.
xml model, we detect faces in the given frame. Once we identify all the faces, we will store them in one list to compare each of them with saved faces.we will use dlib for face comparison.
dlib 68 point face landmark detection will give you landmarks for given face. We do have some known face landmarks stored in numpy files which we will load before comparison. Once we have all the landmarks, we will find distance between those landmarks.
We are using 0.6 as threshold. The face landmark which gives you the smallest distance below threshold is the known person entering into the room.
If the value is not below threshold then, its an intruder!You can find full code at the following git repository,smitshilu/AISecurityCameraContribute to smitshilu/AISecurityCamera development by creating an account on can develop a Smart Camera at home to get status regarding an intruder. You can also use services like AWS or Google Cloud to send notifications to your phone or SMS.
If you like this article, please do follow me on Medium or Github or subscribe to my YouTube channel
Shenzhen TigerWong Technology Co.,Ltd
Tel: +86 0755-23773884
Add: Room 601-605, Building 6, 1980 Science and Technology Industrial Park, Longhua Street, Longhua District, Shenzhen