【DIY】BW21-CBV-Kit: Face Recognition Based Access Control System

Introduction

This access control system based on face recognition displays the open and close status of the access on an OLED screen.

 

  • On Startup: It is in recognition mode.
  • Mode Switching: Switch modes using serial port commands.
  1. Send R: Enter registration mode.
  2. In registration mode, send REG = Alice: to register facial information; send DEL = Alice: to delete registered facial information.
  3. Send Y: Save the registered facial information and switch back to recognition mode.
  4. After rebooting the device, it will directly enter recognition mode and load the pre - registered facial information.

Code

Open Arduino IDE, create a new project, and add the following code:

/*

 Access control system based on face recognition (the system starts in recognition mode)

To use this system:

1.Upload the code and open serial monitor

2.Starts directly in recognition mode

3.Serial input 'R' switches to registration mode

4.Register faces using "REG=Name" commands

5.When done, send "Y" to save and switch back to recognition mode

6.In recognition mode, the OLED will show OPEN/CLOSE status

*/

#include "WiFi.h"#include "StreamIO.h"#include "VideoStream.h"#include "RTSP.h"#include "NNFaceDetectionRecognition.h"#include "VideoStreamOverlay.h"#include "AmebaFatFS.h"#include <U8g2lib.h>  // Include U8g2 library for OLED

#define CHANNELVID  0    // Channel for RTSP streaming#define CHANNELJPEG 1    // Channel for taking snapshots#define CHANNELNN   3    // RGB format video for NN only available on channel 3

// Customised resolution for NN#define NNWIDTH  576#define NNHEIGHT 320

// U8g2 OLED setup - adjust according to your OLED modelU8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

VideoSetting configVID(VIDEO_FHD, 30, VIDEO_H264, 0);VideoSetting configJPEG(VIDEO_FHD, CAM_FPS, VIDEO_JPEG, 1);VideoSetting configNN(NNWIDTH, NNHEIGHT, 10, VIDEO_RGB, 0);

NNFaceDetectionRecognition facerecog;

RTSP rtsp;StreamIO videoStreamer(1, 1);StreamIO videoStreamerFDFR(1, 1);StreamIO videoStreamerRGBFD(1, 1);

char ssid[] = "xxx";    // your network SSID (name)char pass[] = "xxx";        // your network passwordint status = WL_IDLE_STATUS;

bool regMode = false;       // Start in recognition modebool accessGranted = false; // Track access statusuint32_t img_addr = 0;uint32_t img_len = 0;

String fileName;long counter = 0;

// File Initialization

AmebaFatFS fs;

void updateOLEDStatus() {

    u8g2.clearBuffer();

    if (regMode) {

        u8g2.drawStr(0, 20, "REGISTER MODE");

        u8g2.drawStr(0, 40, "REG=<NAME>");

        u8g2.drawStr(0, 60, "Enter 'Y' to save");

    } else {

        u8g2.drawStr(0, 20, "RECOGNITION MODE");

        u8g2.drawStr(0, 40, accessGranted ? "Status: OPEN" : "Status: CLOSE");

    }

    u8g2.sendBuffer();

}

void setup(){

    // Initialize OLED display

    u8g2.begin();

    u8g2.clearBuffer();

    u8g2.setFont(u8g2_font_ncenB10_tr);

    u8g2.drawStr(0, 20, "Initializing...");

    u8g2.sendBuffer();

 

    Serial.begin(115200);

 

    // Attempt to connect to Wifi network:

    while (status != WL_CONNECTED) {

        Serial.print(...
Read more »