From 0266875718d143668b1d99917768583bd5ef007a Mon Sep 17 00:00:00 2001 From: yuanjiong Date: Wed, 20 Oct 2021 20:16:02 +0800 Subject: [PATCH] :sparkles: add face_recognition examples --- .../human_face_recognition/lcd/CMakeLists.txt | 8 ++ .../lcd/main/CMakeLists.txt | 5 ++ .../lcd/main/app_main.cpp | 30 +++++++ .../lcd/main/event_logic.cpp | 84 +++++++++++++++++++ .../lcd/main/event_logic.hpp | 13 +++ .../human_face_recognition/lcd/partitions.csv | 5 ++ .../lcd/sdkconfig.defaults | 12 +++ .../lcd/sdkconfig.defaults.esp32s3 | 15 ++++ .../terminal/CMakeLists.txt | 8 ++ .../terminal/main/CMakeLists.txt | 5 ++ .../terminal/main/app_main.cpp | 25 ++++++ .../terminal/main/event_logic.cpp | 84 +++++++++++++++++++ .../terminal/main/event_logic.hpp | 13 +++ .../terminal/partitions.csv | 5 ++ .../terminal/sdkconfig.defaults | 12 +++ .../terminal/sdkconfig.defaults.esp32 | 4 + .../terminal/sdkconfig.defaults.esp32s2 | 7 ++ .../terminal/sdkconfig.defaults.esp32s3 | 15 ++++ 18 files changed, 350 insertions(+) create mode 100644 examples/human_face_recognition/lcd/CMakeLists.txt create mode 100644 examples/human_face_recognition/lcd/main/CMakeLists.txt create mode 100755 examples/human_face_recognition/lcd/main/app_main.cpp create mode 100644 examples/human_face_recognition/lcd/main/event_logic.cpp create mode 100644 examples/human_face_recognition/lcd/main/event_logic.hpp create mode 100644 examples/human_face_recognition/lcd/partitions.csv create mode 100644 examples/human_face_recognition/lcd/sdkconfig.defaults create mode 100644 examples/human_face_recognition/lcd/sdkconfig.defaults.esp32s3 create mode 100644 examples/human_face_recognition/terminal/CMakeLists.txt create mode 100644 examples/human_face_recognition/terminal/main/CMakeLists.txt create mode 100755 examples/human_face_recognition/terminal/main/app_main.cpp create mode 100644 examples/human_face_recognition/terminal/main/event_logic.cpp create mode 100644 examples/human_face_recognition/terminal/main/event_logic.hpp create mode 100644 examples/human_face_recognition/terminal/partitions.csv create mode 100644 examples/human_face_recognition/terminal/sdkconfig.defaults create mode 100644 examples/human_face_recognition/terminal/sdkconfig.defaults.esp32 create mode 100644 examples/human_face_recognition/terminal/sdkconfig.defaults.esp32s2 create mode 100644 examples/human_face_recognition/terminal/sdkconfig.defaults.esp32s3 diff --git a/examples/human_face_recognition/lcd/CMakeLists.txt b/examples/human_face_recognition/lcd/CMakeLists.txt new file mode 100644 index 0000000..f3c0cfb --- /dev/null +++ b/examples/human_face_recognition/lcd/CMakeLists.txt @@ -0,0 +1,8 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS ../../../components) +add_compile_options(-fdiagnostics-color=always) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(human_face_recognition_lcd) diff --git a/examples/human_face_recognition/lcd/main/CMakeLists.txt b/examples/human_face_recognition/lcd/main/CMakeLists.txt new file mode 100644 index 0000000..0f71747 --- /dev/null +++ b/examples/human_face_recognition/lcd/main/CMakeLists.txt @@ -0,0 +1,5 @@ +set(src_dirs .) + +set(include_dirs .) + +idf_component_register(SRC_DIRS ${src_dirs} INCLUDE_DIRS ${include_dirs}) \ No newline at end of file diff --git a/examples/human_face_recognition/lcd/main/app_main.cpp b/examples/human_face_recognition/lcd/main/app_main.cpp new file mode 100755 index 0000000..6bb5a3b --- /dev/null +++ b/examples/human_face_recognition/lcd/main/app_main.cpp @@ -0,0 +1,30 @@ +#include "who_camera.h" +#include "who_human_face_recognition.hpp" +#include "who_lcd.h" +#include "who_button.h" +#include "event_logic.hpp" +#include "who_adc_button.h" + +static QueueHandle_t xQueueAIFrame = NULL; +static QueueHandle_t xQueueLCDFrame = NULL; +static QueueHandle_t xQueueKeyState = NULL; +static QueueHandle_t xQueueEventLogic = NULL; +static button_adc_config_t buttons[4] = {{1, 2800, 3000}, {2, 2250, 2450}, {3, 300, 500}, {4, 850, 1050}}; + +#define GPIO_BOOT GPIO_NUM_0 + +extern "C" void app_main() +{ + xQueueAIFrame = xQueueCreate(2, sizeof(camera_fb_t *)); + xQueueLCDFrame = xQueueCreate(2, sizeof(camera_fb_t *)); + xQueueKeyState = xQueueCreate(1, sizeof(int *)); + xQueueEventLogic = xQueueCreate(1, sizeof(int *)); + + register_camera(PIXFORMAT_RGB565, FRAMESIZE_240X240, 2, xQueueAIFrame); + register_button(GPIO_BOOT, xQueueKeyState); + // register_adc_button(buttons, 4, xQueueKeyState); + register_event(xQueueKeyState, xQueueEventLogic); + register_human_face_recognition(xQueueAIFrame, xQueueEventLogic, NULL, xQueueLCDFrame, false); + register_lcd(xQueueLCDFrame, NULL, true); + +} diff --git a/examples/human_face_recognition/lcd/main/event_logic.cpp b/examples/human_face_recognition/lcd/main/event_logic.cpp new file mode 100644 index 0000000..08adeaa --- /dev/null +++ b/examples/human_face_recognition/lcd/main/event_logic.cpp @@ -0,0 +1,84 @@ +#include +#include "event_logic.hpp" +#include "who_button.h" +#include "who_human_face_recognition.hpp" + +typedef enum +{ + MENU = 1, + PLAY, + UP, + DOWN +}key_name_t; + +static QueueHandle_t xQueueKeyStateI = NULL; +static QueueHandle_t xQueueEventO = NULL; +static key_state_t key_state; +static key_name_t adc_button_name; +static recognizer_state_t recognizer_state; + +void event_generate(void *arg) +{ + while (1) + { + xQueueReceive(xQueueKeyStateI, &key_state, portMAX_DELAY); + switch (key_state) + { + case KEY_SHORT_PRESS: + recognizer_state = RECOGNIZE; + break; + + case KEY_LONG_PRESS: + recognizer_state = ENROLL; + break; + + case KEY_DOUBLE_CLICK: + recognizer_state = DELETE; + break; + + default: + recognizer_state = DETECT; + break; + } + xQueueSend(xQueueEventO, &recognizer_state, portMAX_DELAY); + } +} + + +void event_generate_from_adc_button(void *arg) +{ + while (1) + { + xQueueReceive(xQueueKeyStateI, &adc_button_name, portMAX_DELAY); + switch (adc_button_name) + { + case MENU: + recognizer_state = ENROLL; + break; + + case PLAY: + recognizer_state = DELETE; + break; + + case UP: + recognizer_state = RECOGNIZE; + break; + + case DOWN: + recognizer_state = RECOGNIZE; + break; + + default: + recognizer_state = DETECT; + break; + } + xQueueSend(xQueueEventO, &recognizer_state, portMAX_DELAY); + } +} + +void register_event(const QueueHandle_t key_state_i, const QueueHandle_t event_o) +{ + xQueueKeyStateI = key_state_i; + xQueueEventO = event_o; + xTaskCreatePinnedToCore(event_generate, "event_logic_task", 1024, NULL, 5, NULL, 0); +} \ No newline at end of file diff --git a/examples/human_face_recognition/lcd/main/event_logic.hpp b/examples/human_face_recognition/lcd/main/event_logic.hpp new file mode 100644 index 0000000..9468ba0 --- /dev/null +++ b/examples/human_face_recognition/lcd/main/event_logic.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" +#include "freertos/task.h" + +/** + * @brief + * + * @param key_state_i + * @param event_o + */ +void register_event(const QueueHandle_t key_state_i, const QueueHandle_t event_o); \ No newline at end of file diff --git a/examples/human_face_recognition/lcd/partitions.csv b/examples/human_face_recognition/lcd/partitions.csv new file mode 100644 index 0000000..d6fdf11 --- /dev/null +++ b/examples/human_face_recognition/lcd/partitions.csv @@ -0,0 +1,5 @@ +# Name, Type, SubType, Offset, Size, Flags +# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild +factory, app, factory, 0x010000, 3840K +nvs, data, nvs, 0x3D0000, 16K +fr, 32, 32, 0x3E0000, 128K diff --git a/examples/human_face_recognition/lcd/sdkconfig.defaults b/examples/human_face_recognition/lcd/sdkconfig.defaults new file mode 100644 index 0000000..2b2b87f --- /dev/null +++ b/examples/human_face_recognition/lcd/sdkconfig.defaults @@ -0,0 +1,12 @@ +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y + +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y + +CONFIG_SPIRAM_SPEED_80M=y +CONFIG_SPIRAM_USE_CAPS_ALLOC=y + +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" + +CONFIG_S16=y \ No newline at end of file diff --git a/examples/human_face_recognition/lcd/sdkconfig.defaults.esp32s3 b/examples/human_face_recognition/lcd/sdkconfig.defaults.esp32s3 new file mode 100644 index 0000000..522de61 --- /dev/null +++ b/examples/human_face_recognition/lcd/sdkconfig.defaults.esp32s3 @@ -0,0 +1,15 @@ +CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32S3_SPIRAM_SUPPORT=y + +CONFIG_ESP32S3_DATA_CACHE_64KB=y +CONFIG_ESP32S3_DATA_CACHE_8WAYS=y +CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y + +CONFIG_CAMERA_MODULE_ESP_S3_EYE=y +CONFIG_LCD_DRIVER_SCREEN_CONTROLLER_ST7789=y +CONFIG_ESPTOOLPY_NO_STUB=y +CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y + +CONFIG_SPIRAM_MODE_OCT=y + +CONFIG_S8=y diff --git a/examples/human_face_recognition/terminal/CMakeLists.txt b/examples/human_face_recognition/terminal/CMakeLists.txt new file mode 100644 index 0000000..fa8a4b8 --- /dev/null +++ b/examples/human_face_recognition/terminal/CMakeLists.txt @@ -0,0 +1,8 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS ../../../components) +add_compile_options(-fdiagnostics-color=always) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(human_face_recognition_terminal) diff --git a/examples/human_face_recognition/terminal/main/CMakeLists.txt b/examples/human_face_recognition/terminal/main/CMakeLists.txt new file mode 100644 index 0000000..0f71747 --- /dev/null +++ b/examples/human_face_recognition/terminal/main/CMakeLists.txt @@ -0,0 +1,5 @@ +set(src_dirs .) + +set(include_dirs .) + +idf_component_register(SRC_DIRS ${src_dirs} INCLUDE_DIRS ${include_dirs}) \ No newline at end of file diff --git a/examples/human_face_recognition/terminal/main/app_main.cpp b/examples/human_face_recognition/terminal/main/app_main.cpp new file mode 100755 index 0000000..a96e98a --- /dev/null +++ b/examples/human_face_recognition/terminal/main/app_main.cpp @@ -0,0 +1,25 @@ +#include "who_camera.h" +#include "who_human_face_recognition.hpp" +#include "who_button.h" +#include "event_logic.hpp" +#include "who_adc_button.h" + +static QueueHandle_t xQueueAIFrame = NULL; +static QueueHandle_t xQueueKeyState = NULL; +static QueueHandle_t xQueueEventLogic = NULL; +static button_adc_config_t buttons[4] = {{1, 2800, 3000}, {2, 2250, 2450}, {3, 300, 500}, {4, 850, 1050}}; + +#define GPIO_BOOT GPIO_NUM_0 + +extern "C" void app_main() +{ + xQueueAIFrame = xQueueCreate(2, sizeof(camera_fb_t *)); + xQueueKeyState = xQueueCreate(1, sizeof(int *)); + xQueueEventLogic = xQueueCreate(1, sizeof(int *)); + + register_camera(PIXFORMAT_RGB565, FRAMESIZE_240X240, 2, xQueueAIFrame); + register_button(GPIO_BOOT, xQueueKeyState); + register_event(xQueueKeyState, xQueueEventLogic); + register_human_face_recognition(xQueueAIFrame, xQueueEventLogic, NULL, NULL, true); + +} diff --git a/examples/human_face_recognition/terminal/main/event_logic.cpp b/examples/human_face_recognition/terminal/main/event_logic.cpp new file mode 100644 index 0000000..08adeaa --- /dev/null +++ b/examples/human_face_recognition/terminal/main/event_logic.cpp @@ -0,0 +1,84 @@ +#include +#include "event_logic.hpp" +#include "who_button.h" +#include "who_human_face_recognition.hpp" + +typedef enum +{ + MENU = 1, + PLAY, + UP, + DOWN +}key_name_t; + +static QueueHandle_t xQueueKeyStateI = NULL; +static QueueHandle_t xQueueEventO = NULL; +static key_state_t key_state; +static key_name_t adc_button_name; +static recognizer_state_t recognizer_state; + +void event_generate(void *arg) +{ + while (1) + { + xQueueReceive(xQueueKeyStateI, &key_state, portMAX_DELAY); + switch (key_state) + { + case KEY_SHORT_PRESS: + recognizer_state = RECOGNIZE; + break; + + case KEY_LONG_PRESS: + recognizer_state = ENROLL; + break; + + case KEY_DOUBLE_CLICK: + recognizer_state = DELETE; + break; + + default: + recognizer_state = DETECT; + break; + } + xQueueSend(xQueueEventO, &recognizer_state, portMAX_DELAY); + } +} + + +void event_generate_from_adc_button(void *arg) +{ + while (1) + { + xQueueReceive(xQueueKeyStateI, &adc_button_name, portMAX_DELAY); + switch (adc_button_name) + { + case MENU: + recognizer_state = ENROLL; + break; + + case PLAY: + recognizer_state = DELETE; + break; + + case UP: + recognizer_state = RECOGNIZE; + break; + + case DOWN: + recognizer_state = RECOGNIZE; + break; + + default: + recognizer_state = DETECT; + break; + } + xQueueSend(xQueueEventO, &recognizer_state, portMAX_DELAY); + } +} + +void register_event(const QueueHandle_t key_state_i, const QueueHandle_t event_o) +{ + xQueueKeyStateI = key_state_i; + xQueueEventO = event_o; + xTaskCreatePinnedToCore(event_generate, "event_logic_task", 1024, NULL, 5, NULL, 0); +} \ No newline at end of file diff --git a/examples/human_face_recognition/terminal/main/event_logic.hpp b/examples/human_face_recognition/terminal/main/event_logic.hpp new file mode 100644 index 0000000..9468ba0 --- /dev/null +++ b/examples/human_face_recognition/terminal/main/event_logic.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" +#include "freertos/task.h" + +/** + * @brief + * + * @param key_state_i + * @param event_o + */ +void register_event(const QueueHandle_t key_state_i, const QueueHandle_t event_o); \ No newline at end of file diff --git a/examples/human_face_recognition/terminal/partitions.csv b/examples/human_face_recognition/terminal/partitions.csv new file mode 100644 index 0000000..d6fdf11 --- /dev/null +++ b/examples/human_face_recognition/terminal/partitions.csv @@ -0,0 +1,5 @@ +# Name, Type, SubType, Offset, Size, Flags +# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild +factory, app, factory, 0x010000, 3840K +nvs, data, nvs, 0x3D0000, 16K +fr, 32, 32, 0x3E0000, 128K diff --git a/examples/human_face_recognition/terminal/sdkconfig.defaults b/examples/human_face_recognition/terminal/sdkconfig.defaults new file mode 100644 index 0000000..2b2b87f --- /dev/null +++ b/examples/human_face_recognition/terminal/sdkconfig.defaults @@ -0,0 +1,12 @@ +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y + +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y + +CONFIG_SPIRAM_SPEED_80M=y +CONFIG_SPIRAM_USE_CAPS_ALLOC=y + +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" + +CONFIG_S16=y \ No newline at end of file diff --git a/examples/human_face_recognition/terminal/sdkconfig.defaults.esp32 b/examples/human_face_recognition/terminal/sdkconfig.defaults.esp32 new file mode 100644 index 0000000..ecc2d87 --- /dev/null +++ b/examples/human_face_recognition/terminal/sdkconfig.defaults.esp32 @@ -0,0 +1,4 @@ +CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32_SPIRAM_SUPPORT=y + +CONFIG_CAMERA_MODULE_ESP_EYE=y \ No newline at end of file diff --git a/examples/human_face_recognition/terminal/sdkconfig.defaults.esp32s2 b/examples/human_face_recognition/terminal/sdkconfig.defaults.esp32s2 new file mode 100644 index 0000000..3b5e99c --- /dev/null +++ b/examples/human_face_recognition/terminal/sdkconfig.defaults.esp32s2 @@ -0,0 +1,7 @@ +CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32S2_SPIRAM_SUPPORT=y + +CONFIG_ESP32S2_DATA_CACHE_16KB=y +ESP32S2_DATA_CACHE_LINE_32B=y + +CONFIG_CAMERA_MODULE_ESP_S2_KALUGA=y \ No newline at end of file diff --git a/examples/human_face_recognition/terminal/sdkconfig.defaults.esp32s3 b/examples/human_face_recognition/terminal/sdkconfig.defaults.esp32s3 new file mode 100644 index 0000000..522de61 --- /dev/null +++ b/examples/human_face_recognition/terminal/sdkconfig.defaults.esp32s3 @@ -0,0 +1,15 @@ +CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32S3_SPIRAM_SUPPORT=y + +CONFIG_ESP32S3_DATA_CACHE_64KB=y +CONFIG_ESP32S3_DATA_CACHE_8WAYS=y +CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y + +CONFIG_CAMERA_MODULE_ESP_S3_EYE=y +CONFIG_LCD_DRIVER_SCREEN_CONTROLLER_ST7789=y +CONFIG_ESPTOOLPY_NO_STUB=y +CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y + +CONFIG_SPIRAM_MODE_OCT=y + +CONFIG_S8=y