【2024 DigiKey Creative Competition】Design and implementation of facial recognition access control system
[Copy link]
This post was last edited by Juggernaut on 2024-11-3 23:22
1. Introduction
With the continuous development of science and technology, people's living standards have been greatly improved. At the same time, people's requirements for security are getting higher and higher. Door locks have always been a key item for family security. The development of door locks has gone from ordinary physical door locks to password locks, fingerprint locks to other more advanced door locks that use biometric recognition technology. Among them, multifunctional smart door locks based on face recognition technology have become an extremely important part of the development of smart home field.
This project mainly designs a face recognition access control system. It uses OpenMV4 H7 R2 from Xingtong Technology to serve as both the main control function and the camera body. At the same time, an external MG90S servo is used to simulate the opening and closing of the door lock. The OpenMV4 camera is used for face recognition and checks whether it is a specific person. If so, the access control is opened and the green light is on. Otherwise, the red light flashes to prompt illegal users.
2. System Design
The OpenMV4 camera has two functions, the main control and the camera. First, it loops to collect images, compares the facial features saved in OpenMV4, and finds the most matching face. If it is the right one, it notifies the servo to operate and turns on the green LED to prompt the door to open. Otherwise, it turns on the red LED to warn. The specific business process diagram is as follows.
3. Project Hardware
- OpenMV4 Camera
The OpenMV4 Camera is a small, low-power, low-cost board that makes it easy to implement machine vision applications. It can be scripted in a high-level language, Python (MicroPython to be exact), rather than C/C++. Python's high-level data structures make it easy to handle complex outputs in machine vision algorithms.
The OpenMV4 is powered by a STM32H743VI ARM Cortex M7 processor, 480 MHz, with 1MB RAM and 2 MB flash.
- MG90S Servo
MG90S is a 360-degree servo, which is essentially controlled by outputting PWM waves. The working principle of the servo is very simple, that is, it is controlled by the PWM wave output by the microcontroller. The servo will calculate the required rotation angle based on the duty cycle of the signal, and MG90S cannot control the rotation angle, so its duty cycle is used to control the speed and direction of the servo.
4. Specific Implementation
- The local sample image library
creates a new singtown folder in the TF card of the OpenMV4 camera, and then creates 10 person folders. According to the sequence number, the picture of the first person is saved in the s1 folder, the picture of the second person is saved in the s2 folder, and so on, which can be used for face detection and comparison.
- Face detection
Due to the limited performance of OpenMV4, it is impossible to use the mobilenet library for inference through the nn library. Only LBP features can be used to identify faces. The specific source code is as follows:
import sensor, time, image
from pyb import Servo
from pyb import LED
sensor.reset() # Initialize the camera sensor.
s1 = Servo(1) # P7
red_led = LED(1)
green_led = LED(2)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.HQVGA)
sensor.set_windowing((92,112))
sensor.skip_frames(10) # Let new settings take affect.
sensor.skip_frames(time = 5000) #等待5s
NUM_SUBJECTS = 2
NUM_SUBJECTS_IMGS = 20
img = sensor.snapshot()
d0 = img.find_lbp((0, 0, img.width(), img.height()))
#d0为当前人脸的lbp特征
img = None
pmin = 999999
num=0
def min(pmin, a, s):
global num
if a<pmin:
pmin=a
num=s
return pmin
for s in range(1, NUM_SUBJECTS+1):
dist = 0
for i in range(2, NUM_SUBJECTS_IMGS+1):
img = image.Image("singtown/s%d/%d.pgm"%(s, i))
d1 = img.find_lbp((0, 0, img.width(), img.height()))
#d1为第s文件夹中的第i张图片的lbp特征
dist += image.match_descriptor(d0, d1)
pmin = min(pmin, dist/NUM_SUBJECTS_IMGS, s)
print(pmin)
print(num)
if num == 2:
img.draw_rectangle(r)
s1.angle(100) # 控制舵机旋转到100度
green_led.on()
time.sleep(3) # 等待3秒钟
s1.angle(0) # 将舵机归位到0度
green_led.off()
else:
red_led .on()
time.sleep(3) # 等待3秒钟
red_led .off()
- The servo control
uses the Servo library of OPENMV directly. When the face recognition is accurate, it rotates 100 degrees, then waits for 3 seconds before rotating back.
s1.angle(100) # 控制舵机旋转到100度
time.sleep(3) # 等待3秒钟
s1.angle(0) # 将舵机归位到0度
- LED Control
Directly use the OPENMV LED library. When the face recognition is accurate, the green light will be on for 3 seconds, and when it is wrong, the red light will be on for 3 seconds.
red_led .on()
time.sleep(3) # 等待3秒钟
red_led .off()
5. Run the test
Here’s a family photo first. Since the M90S requires a separate 5V power supply, it can only be powered externally, and the PWM control line can be connected to OPENMV4.
Let's do a face test. It can be seen that a specific face has been recognized and the servo controls the door to open. See the video for details.
The video is here:
Attachment (word + source code):
Finally, thanks to DigiKey & eeworld for organizing the event.
|