There are many person recognition systems that use signatures, fingerprints, voice, hand geometry, face recognition, etc., to identify people, but there are no face recognition systems.
Face recognition systems can be used not only for security purposes to identify people in public places, but also for attendance purposes in offices and schools.
In this project, we will build a face recognition system using ESP32-CAM, which can also be used as an ESP32-CAM security system by recognizing the face of an unauthorized person. The ESP32-CAM is a very small camera module that uses the ESP32-S chip. Using the ESP32-CAM module, we can build a face recognition system without using any complex programming and any additional components.
The AI-Thinker ESP32-CAM module features an ESP32-S chip, an ultra-small OV2640 camera and a micro SD card slot. The Micro SD card slot can be used to store images taken from the camera or to store files. The ESP32-CAM module can be used in a wide range of iot applications. It can be used as a face detection system in offices, schools, and other private areas, as well as for wireless surveillance, QR code wireless recognition, and many other iot applications.
ESP32-CAM modules can be programmed using ESP-IDF or the Arduino IDE. The ESP32-CAM module also has several GPIO pins for connecting to external hardware. The ESP32-CAM does not have a USB connector, so to program the module, you need an FTDI board.
Features:
The smallest 802.11b/g/n Wi-Fi BT SoC module
Low power 32-bit CPU that can also serve application processors
Up to 160MHz clock speed, integrated computing power up to 600 DMIPS
Built-in 520 KB SRAM, external 4MPSRAM
Support UART/SPI/I2C/PWM/ADC/DAC
Supports OV2640 and OV7670 cameras with built-in flash
Support image Wi-Fi upload
TF card support
Supports multiple sleep modes
Embedded Lwip and FreeRTOS
Support STA/AP/STA+AP operation mode
Smart Config/AirKiss technology is supported
Support for local and remote firmware upgrades over serial ports (FOTA)
Specifications:
SPI flash: The default is 32Mbit
Memory: 520KB SRAM+4M PSRAM
TF card support: Max. 4G
Supported interfaces: UART, SPI, I2C, PWM
Image output format: JPEG, BMP, gray scale
IO port: 9
Power supply range: 5V
Required component
ESP32-CAM
FTDI Programmer
Circuit schematic diagram
To build the ESP32 CAM security camera, we only need the ESP32 camera module and FTDI programmer to program it.
The ESP32-CAM does not have a USB connector, so you need an FTDI programmer to upload code to the ESP32-CAM, as shown in the image above. The Vcc and GND pins of the ESP32 are connected to the Vcc and GND pins of the FTDI board. The Tx and Rx of the ESP32 are connected to the Rx and Tx of the FTDI board.
Note: Ground IO0 before uploading the code. IO0 determines whether the ESP32 is in blinking mode. When GPIO 0 is connected to GND, the ESP32 is in blinking mode.
After programming the ESP32, I removed the FTDI board and connected the module to a 3.3V power supply using the 7805 regulator. The Settings for the ESP32 cam video stream are as follows:
Install the ESP32 Board on the Arduino IDE
Here the ESP32-CAM is programmed using the Arduino IDE. To do this, we have to install the ESP32 plug-in on the Arduino IDE.
To install the ESP32 board in your Arduino IDE, go to File Preferences
Now copy the following link and paste it into the "Additional Board Manager URLs" field, as shown below. Then, click the OK button:
Now to the Board of Tools, the Board Manager
Search for ESP32 in Board Manager and install "ESP32 by Espressif Systems".
ESP32 camera web server code
We already have a sample code from ESP32 cam video streaming and face recognition. Open the ESP32 example using the "File" Examples "ESP32" Camera, then open the CameraWebServer example.
Before uploading the code, you will need to enter your Wi-Fi name and password.
const char* ssid = "WiFi name";
const char* Password = "Password";
Then define the ESP camera module. In the code, they define 5 camera modules, so uncomment "CAMERA_MODEL_AI_THINKER" and comment the remaining modules.
Now the code is ready to upload.
To upload the code, connect the FDTI board to your laptop and select "ESP32 Wrover Module" as your board. Also, change other Settings based on this image:
Before uploading the code, press the ESP32 reset button and then click the Upload button.
Note: If you encounter an error while uploading the code, check that IO0 is connected to GND and that you have selected the correct setting in the Tools menu.
Disconnect the IO0 and GND pins after uploading the code. Then open the serial monitor and change the baud rate to 115200. Then press the ESP32 reset button and it will print the ESP IP address and port number on the serial monitor as shown below.
Now to access the camera stream, navigate to your browser and enter your ESP IP address. It will take you to the streaming media page. To start an ESP32 cam video stream, click the "Start Streaming" button at the bottom of the page
You can change the streaming quality by changing the "resolution" on the streaming page. You can also click the picture by clicking the "Get Still" button, but this code does not have the option to save the picture.
After testing the video stream, now we will test the ESP32 cam face detection and recognition function. Turn on face recognition and detection from Settings:
To do face recognition first, you need to register your face. You can register new faces by clicking on the "Register Faces" option. It takes several attempts to save face. After saving the face, it will detect the face as subject 0, which can now be used as a security system by recognizing the face.
So this is how the ESP camera module can be easily configured for video streaming and facial recognition.
#include “esp_camera.h”
#include
// Warning!! Make sure you select the ESP32 Wrover module,
// or another board with PSRAM enabled
// Select a camera model
//#define CAMERA_MODEL_WROVER_KIT
//#define CAMERA_MODEL_ESP_EYE
//#define CAMERA_MODEL_M5STACK_PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE
#define CAMERA_MODEL_AI_THINKER
#include “camera_pins.h”
const char* ssid = "Galaxy-M20 ";
const char* Password = "ac312124";
Invalid startCameraServer();
Invalid Settings () {
Serial number. Start (115200);
Serial.setDebugOutput(true);
Serial number.println ();
camera_config_t configuration;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
pin_href = HREF_GPIO_NUM; config.pin_href = href_gPIo_num;
pin_sscb_sda = SIOD_GPIO_NUM;
pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
// Initialize with high specifications to pre-allocate larger buffers
If (psramFound ()) {
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 10;
config.fb_count = 2;
} other {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
}
# If defined (CAMERA_MODEL_ESP_EYE)
pinMode (13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
# in case
// Camera initialization
esp_err_t err = esp_camera_init(&config);
If (wrong! = ESP_OK) {
Serial.printf(" Camera initialization failed, error 0x%x", err);
Back;
}
sensor_t * s = esp_camera_sensor_get();
// The initial sensor is flipped vertically and the color is a little saturated
if (s->id.PID == OV3660_PID) {
s->set_vflip(s, 1); // Flip it back
s->set_brightness(s, 1); // Slightly increase the brightness
s->set_saturation(s, -2); // Reduce the saturation
}
// Reduce the frame size to get a higher initial frame rate
s->set_framesize(s, FRAMESIZE_QVGA);
# If defined (CAMERA_MODEL_M5STACK_WIDE)
s->set_vflip(s, 1);
s->set_hmirror(s, 1);
# in case
WiFi.begin(ssid, password);
And (WiFi.status ()! = WL_CONNECTED) {
Delay (500);
Serial.print(".");
}
Serial number.println ("");
Serial.println("WiFi connection ");
startCameraServer();
Serial.print(" Camera ready! Use 'http://");
Serial.print(WiFi.localIP());
Serial.println("' to connect ");
}
Invalid loop () {
// Put your main code here and repeat:
Delay (10000);