ESP32 cam face recognition enrolled faces are not saved

I am using the code from the Tools->Example->ESP32->Camera->CameraWebServer code to run face recognition on my browser. But the enrolled faces get lost after a browser reload or disconnect-reconnect of power.

How can I save the enrolled faces in the ESP32 cam so that I don't have to enroll everytime after reloading the browser or reconnecting the power? Thanks in advance.

To save the enrolled faces on the ESP32 cam, you will need to store them in a non-volatile memory such as the flash memory. The flash memory on the ESP32 can be used to store data that persists even after a power cycle or a browser reload.

In the CameraWebServer example code, the enrolled faces are stored in the SPIFFS file system. However, the SPIFFS file system is stored in the flash memory, so it is possible to save the enrolled faces directly in the flash memory as well.

To save the enrolled faces in the flash memory, you can modify the code that handles the face enrollment to write the faces to a specific location in the flash memory. One option is to use the ESP-IDF's NVS (Non-Volatile Storage) library to store the faces in the flash memory.

Here are the steps you can follow:

  1. Include the NVS header file at the top of the CameraWebServer.ino file:

c++Copy code

#include "nvs.h"
  1. Initialize the NVS library at the beginning of the setup() function:

c++Copy code

nvs_flash_init();
  1. Create a new NVS namespace for storing the faces. You can do this by adding the following code to the setup() function:

c++Copy code

nvs_handle_t nvs_handle;
nvs_open("face_data", NVS_READWRITE, &nvs_handle);

This code creates a new NVS namespace called "face_data" and opens it for reading and writing.

  1. Modify the code that handles the face enrollment to write the faces to the NVS namespace. You can use the NVS library functions to write the data to the flash memory. Here is an example of how to write a single face:

c++Copy code

nvs_set_blob(nvs_handle, "face_0", faceData, faceDataSize);

This code writes the face data to the "face_0" key in the "face_data" namespace.

You will need to modify the enrollment code to write all the enrolled faces to the flash memory. You can use a for loop to iterate over all the enrolled faces and write them to the NVS namespace.

  1. To load the enrolled faces from the flash memory when the ESP32 boots up, you can add code to the setup() function to read the faces from the NVS namespace and load them into the face recognition library. Here is an example of how to read a single face:

c++Copy code

size_t faceDataSize;
nvs_get_blob(nvs_handle, "face_0", NULL, &faceDataSize);
uint8_t* faceData = (uint8_t*) malloc(faceDataSize);
nvs_get_blob(nvs_handle, "face_0", faceData, &faceDataSize);

This code reads the face data from the "face_0" key in the "face_data" namespace and loads it into a buffer called faceData.

You will need to modify this code to read all the enrolled faces from the NVS namespace and load them into the face recognition library.

By following these steps, you should be able to save the enrolled faces in the flash memory and load them back into the face recognition library when the ESP32 boots up.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.