Intelligent Security Camera Based on Face Recognition and Motion Detection

1.Project Introduction

1.1 Project Overview

In residential scenarios, access control security and dynamic monitoring at the door are crucial, yet they are often difficult to ensure efficiently due to the limitations of traditional methods. To address this issue, we have developed an intelligent security camera based on face recognition and motion detection technologies, which is applied to access control systems to safeguard residential security.

This smart security camera has two functions. The first is smart unlocking, which enables door opening through facial recognition after registering the house owner's information. The second is security monitoring, which triggers an alarm when a stranger stays at the door for a long time or the camera is blocked.

This smart security camera is made using UNIHIKER K10, a servo, and other components. It realizes face unlocking and security monitoring through the built-in facial recognition and motion detection functions of UNIHIKER K10, and simulates the door opening and closing effect through servo control.

1.2 Project Functional Diagrams

1.3 Project Video

2.Materials List

2.1 Hardware list

HARDWARE LIST
1 UNIHIKER K10
1 USB-C Cable
1 180° Servo
1 Button
1 PH2.0-3P Male-to-Male Cable

Meanwhile, we have also created a K10-servo door structure. It is included in the file named "K10 Servo Door Structure", and those in need can download and use it.

2.2 Software

Mind+ Graphical Programming Software (Minimum Version Requirement: V1.8.1 RC1.0)

2.3 Basic Mind+ Software Usage

(1) Double click to open the Mind

The following screen will be called up.

Click and switch to offline mode.

(2) Load UNIHIKER K10


Based on the previous steps, then click on "Extensions" find the "UNIHIKER K10" module under the "Board" and click to add it. After clicking "Back" you can find the UNIHIKER K10 in the "Command Area" and complete the loading of UNIHIKER K10.

Then,you need to use a USB cable to connect the UNIHIKER K10 to the computer.

Then, after clicking Connect Device, click COM7-UNIHIKER K10 to connect.

Note: The device name of different UNIHIKER K10 may vary, but all end with K10.

In Windows 10/11, the UNIHIKER K10 is driver-free. However, for Windows 7, manual driver installation is required: https://www.unihiker.com/wiki/K10/faq/#high-frequency-problem.

The next interface you see is the Mind+ programming interface. Let's see what this interface consists of.

Note: For a detailed description of each area of the Mind+ interface, see the Knowledge Hub section of this lesson.

3.Construction Steps

We divide the project into the following main tasks:

(1) Face enrollment : Pressing button A allows the owner's facial information to be enrolled (registered) into the system.

(2) Face recognition for door opening: When the door button is pressed, if the owner or an authorized face is recognized, the door opens. If a stranger is recognized, the buzzer will sound like an alarm.

(3) Motion detection for abnormal phenomena: The motion detection algorithm in the camera detects whether there are abnormal behaviors captured by the camera. If it detects that there is no significant change in the scene for a long time (such as someone staying for a long time, trying to block the camera, or other abnormal behaviors), the buzzer will alarm.

3.1 Task1:Face enrollment

Before UNIHIKER K10 can implement facial recognition, face enrollment is required. In this task, we first write a face learning program and run it to enable UNIHIKER K10 to learn the face of the room owner.

(1) Material Preparation

Prepare the following two face photos for face enrollment and face recognition (these photos are AI-generated). The face recognition materials are included in the attachment, which can be downloaded and used as needed.

Use a computer and a card reader to transfer the three audio files to the TF card. Once completed, insert the TF card into the UNIHIKER K10. The files named "a", "b", and "c" are located in the folder named "TF" in the data attachment, and those in need can download them by themselves.

(2) Hardware Setup

Ensure that the UNIHIKER K10 is connected to the computer using a USB cable,Insert the TF card into the card slot of UNIHIKER K10.

Connect the button to the P0 pin of the UNIHIKER K10, and connect the servo to the P1 pin of the UNIHIKER K10. Then install the UNIHIKER K10, button, and servo on the K10 servo door structure as shown in the figure below.

(3) Software Preparation

Make sure that Mind+ is opened and the UNIHIKER board has been successfully loaded. Once confirmed, you can proceed to write the project program.

Since we have an external button and we use an interrupt pin to control the pressing of the button, we need to load the interrupt pin first as shown in the figure below.

(4) Writing the Program

STEP One:Turn on the camera

To enroll in face information on UNIHIKER K10, the first step is to turn on the camera of K10.

As shown in the figure below, select "enable camera show" in "Screen" and place it in the initialization.

STEP Two: set the buttons for face enrollment

Press the A button to activate the face enrollment function

Set that when button A is pressed, it triggers face enrollment (recording) and also enables face forgetting.

In "control", select "wait 1 seconds" and place it between "forget all face ids" and "learn face", so that face enrollment starts after all faces are completely forgotten.

After learning (enrolling) a face, how to determine if face enrollment is successful? We can set prompt information for successful face enrollment:

1.Light up the lights: Find the "turn on" command, select "all", and switch to green. In this way, all LEDs on K10 will light up green after successful enrollment.

2.Broadcast audio: "Face enrollment successful." The voice prompt indicates that face enrollment is successful.

Earlier, we transferred three audio files to the TF card. Among them, the "a" audio plays: "Face enrollment successful." So, as shown in the figure below, we just need to change "music" to "a".

Set to turn off all lights after waiting for 2 seconds.

Click Upload button,When the burning progress reaches 100%, it indicates that the program has been successfully uploaded.

After a successful upload, the effect is as shown in the following video:

3.2 Task2: Face recognition for door opening

Once face enrollment is successful, K10 can recognize the owner's face. Next, we will write a program for face recognition to control the door opening, and at the same time, add a function to trigger an alarm when a stranger is detected breaking in.

(1) Software Preparation

Select "Micro Servo" in "Actuator" and load it.

(2) Writing the Program

STEP One: set the button for face recognition

When the door button is pressed, it switches to face detection mode for facial recognition.

Since we have connected the button to the P0 port of the UNIHIKER K10, the pin level of the P0 port will change when the button is pressed. Therefore, here we use the pin interrupt command to set the trigger time after the button of the P0 port is pressed.

After pressing the button, wait for 1 second to switch to face detection mode for face recognition.

How to determine whether the currently recognized face matches the pre-enrolled face information of the owner? UNIHIKER K10 assigns an ID to each enrolled face. For example, the first enrolled face is assigned ID 1, and the IDs increment sequentially. It can store up to 48 face information entries. Faces that have not been enrolled are assigned a default ID of -1. After face recognition, a face ID result is generated. We can distinguish whether the face belongs to the house owner or a stranger by checking if the ID is 1 or -1.

The face ID can only be obtained after successful face recognition. Therefore, we use the "if-then" statement to determine whether the face recognition is successful, and only after successful recognition will the content within the "if-then" statement be executed.

After successful face recognition, we need to set a variable named "ID" and assign the recognized face ID to this variable "ID".

If ID = 1, it means the recognized face is an enrolled one.

We also need to add an audio prompt. Earlier, we have transferred three audio files to the TF card, and the "b" audio plays: "Recognition successful, the door has been opened." We just need to change "music" to "b".

If ID = -1, it means a stranger is recognized. Add a light prompt: turn on the red light, and after one second, turn off all the lights.

Among the audio files already transferred to the TF card, the "c" file broadcasts the voice message "Identity verification failed." We will change "music" to "c" to prompt for failed identity verification.

When a stranger is detected, an alarm will sound.

STEP Two: Servo Initialization

After installing the servo, we need to test the angle of the servo's horn to ensure that the door is in a closed state under the initial condition. Through testing, it is determined that the initial horn angle of the servo should be 180 degrees.

On the basis of the original program, set the door to 180 degrees in the initial state, indicating that the door is in the closed state.

STEP Three: Set that after successful face recognition, the door opens

When face recognition is successful, the servo connected to pin P1 rotates to 90 degrees, opening the door. After 10 seconds, the servo rotates back to 180 degrees, closing the door.

Click Upload button,When the burning progress reaches 100%, it indicates that the program has been successfully uploaded.

After a successful upload, the effect is as shown in the following video:

3.3 Task3:Motion detection for abnormal phenomena

In addition to the intelligent face access control, we can also add safety monitoring of the outdoor environment. Use motion detection to monitor whether there are abnormal behaviors through the camera. If it is detected that there is no significant change in the screen for a long time (such as someone staying for a long time, trying to block the camera, or other abnormal behaviors), the buzzer will alarm.

(1) Writing the Program

STEP One:Initialization

Select the motion detection mode.

Set motion detection sensitivity. The larger the set value, the more sensitive the detection of movement, with a range of 0-100.If sensitivity is not set when using motion detection, it will default to 50.

STEP Two: Switch back to motion detection mode.

In daily situations, motion detection is needed to monitor the camera for any abnormal conditions. Therefore, after completing face enrollment, wait for three seconds and then switch back to motion detection mode.

STEP Three: Set motion detection t for any abnormal conditions

Since motion detection checks the screen frame by frame, we set a variable "count" to calculate the number of times movement is detected.

Initialize "count" to 0. If no movement is detected in the current frame, increment "count" by 1 for that frame. If movement is detected, reset "count" to 0. Additionally, print whether there is movement in each frame through the serial port, so that we can see whether there is movement in each frame through the serial port.

If the count equals 30, it indicates that there is no significant change in the camera screen for a long time (such as abnormal behaviors like someone staying for a long time or trying to block the camera), and the buzzer will alarm.

Note: Here, for the convenience of demonstration and testing, I have set the buzzer to alarm when "count" reaches 30. In real-life scenarios, the time may be longer. You could set it to 100, 500, 1000... or even longer.

Click Upload button,When the burning progress reaches 100%, it indicates that the program has been successfully uploaded.

After a successful upload, the effect is as shown in the following video:

Prompt: After the program is successfully uploaded, as shown in the figure below, you can observe whether there is movement in each frame of the picture in the window.

Below is the reference for the complete program.

4.Upload the Program and Observe the Effect.

Click Upload button,When the burning progress reaches 100%, it indicates that the program has been successfully uploaded.

STEP:

(1) Face enrollment: The homeowner presses button A to enter face enrollment mode; enroll the faces of themselves and authorized visitors. After successful enrollment, the green light turns on and the audio plays: "Face enrollment successful."

(2) Door opening process: When the owner or visitor arrives, press button B to enter face recognition mode; if recognized as an authorized user, the green light turns on, the audio plays: "Recognition successful, the door has been opened," and the servo motor is activated to open the door; if recognized as a stranger, the red light flashes, the buzzer sounds, and the audio plays: "Identity verification failed."

(3) Security protection: In daily state, it is in motion detection mode, monitoring the dynamics in front of the door in real-time to identify suspicious behaviors: if no significant changes are detected in the screen for a long time (such as abnormal behaviors like someone staying for a long time or trying to block the camera), the buzzer will alarm.

5.Knowledge Hub

5.1What is facial recognition?

Facial recognition is a biometric technology that identifies a person's identity based on facial feature information. It analyzes facial images or video streams through computer programs, extracts unique facial features (such as interocular distance, nose bridge height, jawline contour, etc.), and compares these features with stored facial templates to complete identity verification or recognition.

Its workflow typically includes the following steps:

(1)Face detection: Locate and extract the face area from an image or video.

(2)Feature extraction: Process the detected face to extract unique biometric features (such as facial key points, texture information, etc.).

(3)Feature Comparison: Match the extracted features with the existing feature templates in the database and calculate the similarity.

(4)Result judgment: Determine whether it is the same person based on the similarity threshold and output the recognition result.

Facial recognition is widely used in scenarios such as security monitoring, access control systems, mobile phone unlocking, payment verification, etc., with advantages such as non-contact and fast recognition speed, but also faces challenges such as privacy protection and anti-interference (e.g., lighting, occlusion, pose changes).

5.2 What is motion detection?

Motion Detection is a technology that identifies whether there is object movement within a monitored area through technical means. It mainly compares consecutive image frames or video frames, analyzes pixel changes, and when the changes exceed a preset threshold, it determines that there is object movement and triggers corresponding responses (such as alarms, recording, push notifications, etc.).

Common implementation methods include:

(1)Frame difference method: Compare the differences between two or more adjacent frames of images, and detect moving regions by calculating the changes in pixel gray values.

(2)Background Subtraction: First, establish a background model (such as an image of a static scene), then compare the real-time image with the background model, and the difference is the moving target.

(3)Optical flow method: By analyzing the motion trajectories (optical flow) of pixels in an image to determine whether an object is moving, it is suitable for motion analysis in complex scenarios.

Motion detection is widely used in fields such as security monitoring, smart home (e.g., automatic lighting), and dashcams (collision warning), which can effectively improve the safety and automation level of scenarios, but its accuracy may be affected by factors such as light changes and shadow interference.

6.Appendix of Materials

icon Intelligent Security Camera Based on Face Recognition and Motion Detection.zip 3.78MB Download(0)
License
All Rights
Reserved
licensBg
0