diff --git a/components/common/CMakeLists.txt b/components/common/CMakeLists.txt new file mode 100644 index 0000000..3d75f92 --- /dev/null +++ b/components/common/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRC_DIRS . INCLUDE_DIRS include REQUIRES esp32-camera esp-dl) + +component_compile_options(-ffast-math -O3) diff --git a/components/common/Kconfig b/components/common/Kconfig new file mode 100644 index 0000000..2686392 --- /dev/null +++ b/components/common/Kconfig @@ -0,0 +1,310 @@ +menu "ESP-WHO General Configuration" + menu "Camera Configuration" + + choice PIXEL_FORMAT + bool "Select Camera Pixel Format" + default CAMERA_PIXEL_FORMAT_RGB565 + help + Select Camera Pixel Format. + + config CAMERA_PIXEL_FORMAT_RGB565 + bool "RGB565" + config CAMERA_PIXEL_FORMAT_YUV422 + bool "YUV422" + config CAMERA_PIXEL_FORMAT_GRAYSCALE + bool "GRAYSCALE" + config CAMERA_PIXEL_FORMAT_JPEG + bool "JPEG" + config CAMERA_PIXEL_FORMAT_RGB888 + bool "RGB888" + config CAMERA_PIXEL_FORMAT_RAW + bool "RAW" + config CAMERA_PIXEL_FORMAT_RGB444 + bool "RGB444" + config CAMERA_PIXEL_FORMAT_RGB555 + bool "RGB555" + + endchoice + + choice CAMERA_MODULE + bool "Select Camera Pinout" + default CAMERA_MODULE_WROVER_KIT + help + Select Camera Pinout. + + config CAMERA_MODULE_WROVER_KIT + bool "WROVER-KIT With OV2640 Module" + config CAMERA_MODULE_ESP_EYE + bool "ESP-EYE DevKit" + config CAMERA_MODULE_ESP_S3_EYE + bool "ESP-S3-EYE DevKit" + config CAMERA_MODEL_ESP32_CAM_BOARD + bool "ESP32 Camera Development Board" + config CAMERA_MODULE_M5STACK_PSRAM + bool "M5Stack Camera With PSRAM" + config CAMERA_MODULE_M5STACK_WIDE + bool "M5Stack Camera F (Wide)" + config CAMERA_MODULE_AI_THINKER + bool "ESP32-CAM by AI-Thinker" + config CAMERA_MODULE_CUSTOM + bool "Custom Camera Pinout" + endchoice + + config CAMERA_PIN_PWDN + depends on CAMERA_MODULE_CUSTOM + int "Power Down pin" + range -1 33 + default -1 + help + Select Power Down pin or -1 for unmanaged. + + config CAMERA_PIN_RESET + depends on CAMERA_MODULE_CUSTOM + int "Reset pin" + range -1 33 + default -1 + help + Select Camera Reset pin or -1 for software reset. + + config CAMERA_PIN_XCLK + depends on CAMERA_MODULE_CUSTOM + int "XCLK pin" + range 0 33 + default 21 + help + Select Camera XCLK pin. + + config CAMERA_PIN_SIOD + depends on CAMERA_MODULE_CUSTOM + int "SIOD pin" + range 0 33 + default 26 + help + Select Camera SIOD pin. + + config CAMERA_PIN_SIOC + depends on CAMERA_MODULE_CUSTOM + int "SIOC pin" + range 0 33 + default 27 + help + Select Camera SIOC pin. + + config CAMERA_PIN_VSYNC + depends on CAMERA_MODULE_CUSTOM + int "VSYNC pin" + range 0 39 + default 25 + help + Select Camera VSYNC pin. + + config CAMERA_PIN_HREF + depends on CAMERA_MODULE_CUSTOM + int "HREF pin" + range 0 39 + default 23 + help + Select Camera HREF pin. + + config CAMERA_PIN_PCLK + depends on CAMERA_MODULE_CUSTOM + int "PCLK pin" + range 0 39 + default 25 + help + Select Camera PCLK pin. + + config CAMERA_PIN_Y2 + depends on CAMERA_MODULE_CUSTOM + int "Y2 pin" + range 0 39 + default 4 + help + Select Camera Y2 pin. + + config CAMERA_PIN_Y3 + depends on CAMERA_MODULE_CUSTOM + int "Y3 pin" + range 0 39 + default 5 + help + Select Camera Y3 pin. + + config CAMERA_PIN_Y4 + depends on CAMERA_MODULE_CUSTOM + int "Y4 pin" + range 0 39 + default 18 + help + Select Camera Y4 pin. + + config CAMERA_PIN_Y5 + depends on CAMERA_MODULE_CUSTOM + int "Y5 pin" + range 0 39 + default 19 + help + Select Camera Y5 pin. + + config CAMERA_PIN_Y6 + depends on CAMERA_MODULE_CUSTOM + int "Y6 pin" + range 0 39 + default 36 + help + Select Camera Y6 pin. + + config CAMERA_PIN_Y7 + depends on CAMERA_MODULE_CUSTOM + int "Y7 pin" + range 0 39 + default 39 + help + Select Camera Y7 pin. + + config CAMERA_PIN_Y8 + depends on CAMERA_MODULE_CUSTOM + int "Y8 pin" + range 0 39 + default 34 + help + Select Camera Y8 pin. + + config CAMERA_PIN_Y9 + depends on CAMERA_MODULE_CUSTOM + int "Y9 pin" + range 0 39 + default 35 + help + Select Camera Y9 pin. + endmenu + + + menu "LED Illuminator" + config LED_ILLUMINATOR_ENABLED + bool "LED Illuminator Enabled" + default n + help + Enable an LED Flash or IR Illuminator + + config LED_LEDC_PIN + depends on LED_ILLUMINATOR_ENABLED + int "LED Illuminator GPIO Pin" + range 0 33 + default 4 + help + Set a pin to illuminate an onboard LED or IR Illuminator when streaming or taking snapshots. + + config LED_MAX_INTENSITY + depends on LED_ILLUMINATOR_ENABLED + int "LED Maximum Intensity (0-255)" + range 0 255 + default 255 + help + Limit the maximum intensity of the LED while streaming to prevent overheating (0-255). + + choice LED_LEDC_SPEED_MODE + depends on LED_ILLUMINATOR_ENABLED + bool "Select LEDC Timer Speed Mode" + default LED_LEDC_LOW_SPEED_MODE + help + Select a speed mode for the LEDC channel + + config LED_LEDC_LOW_SPEED_MODE + bool "LOW_SPEED_MODE" + config LED_LEDC_HIGH_SPEED_MODE + bool "HIGH_SPEED_MODE" + endchoice + + config LED_LEDC_TIMER + depends on LED_ILLUMINATOR_ENABLED + int "LEDC Timer" + range 0 3 + default 1 + help + Select the LEDC Timer (0-3) + + config LED_LEDC_CHANNEL + depends on LED_ILLUMINATOR_ENABLED + int "LEDC Channel" + range 0 7 + default 1 + help + Select the LEDC Channel (0-7) + endmenu + + + + menu "DL Configuration" + + config DL_ENABLED + bool "Enable Deep-Learning Application" + default y + + choice DL_SELECT_APP + bool "Select Application" + depends on DL_ENABLED + default DL_HUMAN_FACE + + config DL_HUMAN_FACE + bool "Human Face" + config DL_CAT_FACE + bool "Cat Face" + config DL_HUMAN_HAND + bool "Human Hand" + endchoice + + # Human Face Series + choice DL_HUMAN_FACE_DETECTION_S1_MODEL + bool "Select Human Face Detection Stage-1 Model" + depends on DL_HUMAN_FACE + default DL_HUMAN_FACE_DETECTION_S1_MSR01 + + config DL_HUMAN_FACE_DETECTION_S1_MSR01 + bool "HumanFaceDetectMSR01" + endchoice + + config DL_HUMAN_FACE_DETECTION_S2_ENABLED + bool "Enable Human Face Detection Stage-2" + depends on DL_HUMAN_FACE + default y + + choice DL_HUMAN_FACE_DETECTION_S2_MODEL + bool "Select Human Face Detection Stage-2 Model" + depends on DL_HUMAN_FACE_DETECTION_S2_ENABLED + default DL_HUMAN_FACE_DETECTION_S2_MNP01 + + config DL_HUMAN_FACE_DETECTION_S2_MNP01 + bool "HumanFaceDetectMNP01" + endchoice + + + config DL_HUMAN_FACE_RECOGNITION_ENABLED + bool "Enable Human Face Recognition" + depends on DL_HUMAN_FACE_DETECTION_S2_ENABLED + default y + + choice DL_HUMAN_FACE_RECOGNITION_MODEL + bool "Select Human Face Recognition Model" + depends on DL_HUMAN_FACE_RECOGNITION_ENABLED + default DL_HUMAN_FACE_RECOGNITION_XXX + + config DL_HUMAN_FACE_RECOGNITION_XXX + bool "HumanFaceRecognizeXXX" + endchoice + + # Cat Face Series + choice DL_CAT_FACE_DETECTION_MODEL + bool "Select Cat Face Detection Model" + depends on DL_CAT_FACE + default DL_CAT_FACE_DETECTION_MN03 + + config DL_CAT_FACE_DETECTION_MN03 + bool "CatFaceDetectMN03" + endchoice + + + # Human Hand Series + + endmenu +endmenu \ No newline at end of file diff --git a/components/common/app_camera.cpp b/components/common/app_camera.cpp new file mode 100644 index 0000000..d8af9f8 --- /dev/null +++ b/components/common/app_camera.cpp @@ -0,0 +1,120 @@ +#include "app_camera.hpp" + +#include "esp_log.h" +#include "esp_system.h" + +#include "app_define.h" +#include "dl_tool.hpp" + +static const char *TAG = "app_camera"; + +void app_camera_init(framesize_t frame_size, uint8_t jpeg_quality, uint8_t fb_count) +{ + ESP_LOGI(TAG, "Camera module is %s", CAMERA_MODULE_NAME); + +#if CONFIG_CAMERA_MODEL_ESP_EYE || CONFIG_CAMERA_MODEL_ESP32_CAM_BOARD + /* IO13, IO14 is designed for JTAG by default, + * to use it as generalized input, + * firstly declair it as pullup input */ + gpio_config_t conf; + conf.mode = GPIO_MODE_INPUT; + conf.pull_up_en = GPIO_PULLUP_ENABLE; + conf.pull_down_en = GPIO_PULLDOWN_DISABLE; + conf.intr_type = GPIO_INTR_DISABLE; + conf.pin_bit_mask = 1LL << 13; + gpio_config(&conf); + conf.pin_bit_mask = 1LL << 14; + gpio_config(&conf); +#endif + + camera_config_t config; + config.ledc_channel = LEDC_CHANNEL_0; + config.ledc_timer = LEDC_TIMER_0; + config.pin_d0 = CAMERA_PIN_D0; + config.pin_d1 = CAMERA_PIN_D1; + config.pin_d2 = CAMERA_PIN_D2; + config.pin_d3 = CAMERA_PIN_D3; + config.pin_d4 = CAMERA_PIN_D4; + config.pin_d5 = CAMERA_PIN_D5; + config.pin_d6 = CAMERA_PIN_D6; + config.pin_d7 = CAMERA_PIN_D7; + config.pin_xclk = CAMERA_PIN_XCLK; + config.pin_pclk = CAMERA_PIN_PCLK; + config.pin_vsync = CAMERA_PIN_VSYNC; + config.pin_href = CAMERA_PIN_HREF; + config.pin_sscb_sda = CAMERA_PIN_SIOD; + config.pin_sscb_scl = CAMERA_PIN_SIOC; + config.pin_pwdn = CAMERA_PIN_PWDN; + config.pin_reset = CAMERA_PIN_RESET; + config.xclk_freq_hz = XCLK_FREQ_HZ; +#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565 + config.pixel_format = PIXFORMAT_RGB565; +#endif +#if CONFIG_CAMERA_PIXEL_FORMAT_YUV422 + config.pixel_format = PIXFORMAT_YUV422; +#endif +#if CONFIG_CAMERA_PIXEL_FORMAT_GRAYSCALE + config.pixel_format = PIXFORMAT_GRAYSCALE; +#endif +#if CONFIG_CAMERA_PIXEL_FORMAT_JPEG + config.pixel_format = PIXFORMAT_JPEG; +#endif +#if CONFIG_CAMERA_PIXEL_FORMAT_RGB888 + config.pixel_format = PIXFORMAT_RGB888; +#endif +#if CONFIG_CAMERA_PIXEL_FORMAT_RAW + config.pixel_format = PIXFORMAT_RAW; +#endif +#if CONFIG_CAMERA_PIXEL_FORMAT_RGB444 + config.pixel_format = PIXFORMAT_RGB444; +#endif +#if CONFIG_CAMERA_PIXEL_FORMAT_RGB555 + config.pixel_format = PIXFORMAT_RGB555; +#endif + config.frame_size = frame_size; + config.jpeg_quality = jpeg_quality; + config.fb_count = fb_count; + config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; + + // camera init + esp_err_t err = esp_camera_init(&config); + if (err != ESP_OK) + { + ESP_LOGE(TAG, "Camera init failed with error 0x%x", err); + return; + } + + sensor_t *s = esp_camera_sensor_get(); + s->set_vflip(s, 1); //flip it back + //initial sensors are flipped vertically and colors are a bit saturated + if (s->id.PID == OV3660_PID) + { + s->set_brightness(s, 1); //up the blightness just a bit + s->set_saturation(s, -2); //lower the saturation + } +} + +bool app_camera_decode(camera_fb_t *fb, uint16_t **image_ptr) +{ + assert(fb->format == PIXFORMAT_RGB565); + *image_ptr = (uint16_t *)fb->buf; + return true; +} + +bool app_camera_decode(camera_fb_t *fb, uint8_t **image_ptr) +{ + *image_ptr = (uint8_t *)dl::tool::malloc_aligned(fb->height * fb->width * 3, sizeof(uint8_t)); + if (!*image_ptr) + { + ESP_LOGE(TAG, "malloc memory for image rgb888 failed"); + return false; + } + + if (!fmt2rgb888(fb->buf, fb->len, fb->format, *image_ptr)) + { + ESP_LOGE(TAG, "fmt2rgb888 failed"); + dl::tool::free_aligned(*image_ptr); + return false; + } + return true; +} diff --git a/components/common/app_common.cpp b/components/common/app_common.cpp new file mode 100644 index 0000000..eb07fa9 --- /dev/null +++ b/components/common/app_common.cpp @@ -0,0 +1,70 @@ +#include "app_common.hpp" + +#include "dl_image.hpp" +#include "esp_log.h" + +void draw_detection_result(uint16_t *image_ptr, int image_height, int image_width, std::list &results) +{ + int i = 0; + for (std::list::iterator prediction = results.begin(); prediction != results.end(); prediction++, i++) + { + dl::image::draw_hollow_rectangle(image_ptr, image_height, image_width, + DL_MAX(prediction->box[0], 0), + DL_MAX(prediction->box[1], 0), + DL_MAX(prediction->box[2], 0), + DL_MAX(prediction->box[3], 0), + COLOR_GREEN); +#if CONFIG_DL_HUMAN_FACE_DETECTION_S2_ENABLED + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[0], 0), DL_MAX(prediction->keypoint[1], 0), 4, COLOR_RED); // left eye + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[2], 0), DL_MAX(prediction->keypoint[3], 0), 4, COLOR_RED); // mouth left corner + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[4], 0), DL_MAX(prediction->keypoint[5], 0), 4, COLOR_GREEN); // nose + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[6], 0), DL_MAX(prediction->keypoint[7], 0), 4, COLOR_BLUE); // right eye + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[8], 0), DL_MAX(prediction->keypoint[9], 0), 4, COLOR_BLUE); // mouth right corner +#endif + } +} + +void draw_detection_result(uint8_t *image_ptr, int image_height, int image_width, std::list &results) +{ + int i = 0; + for (std::list::iterator prediction = results.begin(); prediction != results.end(); prediction++, i++) + { + dl::image::draw_hollow_rectangle(image_ptr, image_height, image_width, + DL_MAX(prediction->box[0], 0), + DL_MAX(prediction->box[1], 0), + DL_MAX(prediction->box[2], 0), + DL_MAX(prediction->box[3], 0), + COLOR_GREEN); +#if CONFIG_DL_HUMAN_FACE_DETECTION_S2_ENABLED + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[0], 0), DL_MAX(prediction->keypoint[1], 0), 4, COLOR_RED); // left eye + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[2], 0), DL_MAX(prediction->keypoint[3], 0), 4, COLOR_RED); // mouth left corner + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[4], 0), DL_MAX(prediction->keypoint[5], 0), 4, COLOR_GREEN); // nose + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[6], 0), DL_MAX(prediction->keypoint[7], 0), 4, COLOR_BLUE); // right eye + dl::image::draw_point(image_ptr, image_height, image_width, DL_MAX(prediction->keypoint[8], 0), DL_MAX(prediction->keypoint[9], 0), 4, COLOR_BLUE); // mouth right corner +#endif + } +} + +void print_detection_result(std::list &results) +{ + int i = 0; + for (std::list::iterator prediction = results.begin(); prediction != results.end(); prediction++, i++) + { + ESP_LOGI("detection_result", "[%d]: (%3d, %3d, %3d, %3d)" +#if CONFIG_DL_HUMAN_FACE_DETECTION_S2_ENABLED + " | left eye: (%3d, %3d), right eye: (%3d, %3d), nose: (%3d, %3d), mouth left: (%3d, %3d), mouth right: (%3d, %3d)" +#endif + , + i, + prediction->box[0], prediction->box[1], prediction->box[2], prediction->box[3] +#if CONFIG_DL_HUMAN_FACE_DETECTION_S2_ENABLED + , + prediction->keypoint[0], prediction->keypoint[1], // left eye + prediction->keypoint[6], prediction->keypoint[7], // right eye + prediction->keypoint[4], prediction->keypoint[5], // nose + prediction->keypoint[2], prediction->keypoint[3], // mouth left corner + prediction->keypoint[8], prediction->keypoint[9] +#endif + ); + } +} \ No newline at end of file diff --git a/components/common/app_dl.cpp b/components/common/app_dl.cpp new file mode 100644 index 0000000..e69de29 diff --git a/components/common/app_lcd.c b/components/common/app_lcd.c new file mode 100644 index 0000000..e69de29 diff --git a/components/common/app_led.c b/components/common/app_led.c new file mode 100644 index 0000000..115c8c6 --- /dev/null +++ b/components/common/app_led.c @@ -0,0 +1,65 @@ +#include "app_led.h" + +#if CONFIG_LED_ILLUMINATOR_ENABLED +#include "esp_log.h" +#include "driver/ledc.h" + +static const char *TAG = "app_led"; + +#if CONFIG_LED_LEDC_LOW_SPEED_MODE +#define CONFIG_LED_LEDC_SPEED_MODE LEDC_LOW_SPEED_MODE +#else +#define CONFIG_LED_LEDC_SPEED_MODE LEDC_HIGH_SPEED_MODE +#endif + +void app_led_init() +{ + gpio_set_direction(CONFIG_LED_LEDC_PIN, GPIO_MODE_OUTPUT); + ledc_timer_config_t ledc_timer = { + .duty_resolution = LEDC_TIMER_8_BIT, // resolution of PWM duty + .freq_hz = 1000, // frequency of PWM signal + .speed_mode = LEDC_LOW_SPEED_MODE, // timer mode + .timer_num = CONFIG_LED_LEDC_TIMER // timer index + }; + ledc_channel_config_t ledc_channel = { + .channel = CONFIG_LED_LEDC_CHANNEL, + .duty = 0, + .gpio_num = CONFIG_LED_LEDC_PIN, + .speed_mode = LEDC_LOW_SPEED_MODE, + .hpoint = 0, + .timer_sel = CONFIG_LED_LEDC_TIMER}; +#if CONFIG_LED_LEDC_HIGH_SPEED_MODE + ledc_timer.speed_mode = ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE; +#endif + switch (ledc_timer_config(&ledc_timer)) + { + case ESP_ERR_INVALID_ARG: + ESP_LOGE(TAG, "ledc_timer_config() parameter error"); + break; + case ESP_FAIL: + ESP_LOGE(TAG, "ledc_timer_config() Can not find a proper pre-divider number base on the given frequency and the current duty_resolution"); + break; + case ESP_OK: + if (ledc_channel_config(&ledc_channel) == ESP_ERR_INVALID_ARG) + { + ESP_LOGE(TAG, "ledc_channel_config() parameter error"); + } + break; + default: + break; + } + + ESP_LOGE(TAG, "LED has been initialized."); +} + +void app_led_duty(int duty) +{ // Turn LED On or Off + if (duty > CONFIG_LED_MAX_INTENSITY) + duty = CONFIG_LED_MAX_INTENSITY; + + ledc_set_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL, duty); + ledc_update_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL); + ESP_LOGI(TAG, "Set LED intensity to %d", duty); +} + +#endif \ No newline at end of file diff --git a/components/common/include/app_camera.hpp b/components/common/include/app_camera.hpp new file mode 100644 index 0000000..767070d --- /dev/null +++ b/components/common/include/app_camera.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include "esp_camera.h" +#include "app_define.h" + +/** + * @brief Initialize camera + * + * @param frame_size One of + * - FRAMESIZE_96X96, // 96x96 + * - FRAMESIZE_QQVGA, // 160x120 + * - FRAMESIZE_QCIF, // 176x144 + * - FRAMESIZE_HQVGA, // 240x176 + * - FRAMESIZE_240X240, // 240x240 + * - FRAMESIZE_QVGA, // 320x240 + * - FRAMESIZE_CIF, // 400x296 + * - FRAMESIZE_HVGA, // 480x320 + * - FRAMESIZE_VGA, // 640x480 + * - FRAMESIZE_SVGA, // 800x600 + * - FRAMESIZE_XGA, // 1024x768 + * - FRAMESIZE_HD, // 1280x720 + * - FRAMESIZE_SXGA, // 1280x1024 + * - FRAMESIZE_UXGA, // 1600x1200 + * - FRAMESIZE_FHD, // 1920x1080 + * - FRAMESIZE_P_HD, // 720x1280 + * - FRAMESIZE_P_3MP, // 864x1536 + * - FRAMESIZE_QXGA, // 2048x1536 + * - FRAMESIZE_QHD, // 2560x1440 + * - FRAMESIZE_WQXGA, // 2560x1600 + * - FRAMESIZE_P_FHD, // 1080x1920 + * - FRAMESIZE_QSXGA, // 2560x1920 + * @param jpeg_quality Quality of JPEG output. 0-63 lower means higher quality + * @param fb_count Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed) + */ +void app_camera_init(framesize_t frame_size, uint8_t jpeg_quality, uint8_t fb_count); + +/** + * @brief Decode fb into RGB565 + * + * @param fb + * @param image_ptr + * @return true + * @return false + */ +bool app_camera_decode(camera_fb_t *fb, uint16_t **image_ptr); + +/** + * @brief Decode fb into RGB888 + * + * @param fb + * @param image_ptr + * @return true + * @return false + */ +bool app_camera_decode(camera_fb_t *fb, uint8_t **image_ptr); diff --git a/components/common/include/app_common.hpp b/components/common/include/app_common.hpp new file mode 100644 index 0000000..6f344e3 --- /dev/null +++ b/components/common/include/app_common.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include +#include "dl_detect_define.hpp" +#include "app_define.h" + +/** + * @brief Draw detection result on RGB565 image. + * + * @param image_ptr image + * @param image_height height of image + * @param image_width width of image + * @param results detection results + */ +void draw_detection_result(uint16_t *image_ptr, int image_height, int image_width, std::list &results); + +/** + * @brief Draw detection result on RGB888 image. + * + * @param image_ptr image + * @param image_height height of image + * @param image_width width of image + * @param results detection results + */ + +void draw_detection_result(uint8_t *image_ptr, int image_height, int image_width, std::list &results); + +/** + * @brief Print detection result in terminal + * + * @param results detection results + */ +void print_detection_result(std::list &results); diff --git a/components/common/include/app_define.h b/components/common/include/app_define.h new file mode 100644 index 0000000..0119df6 --- /dev/null +++ b/components/common/include/app_define.h @@ -0,0 +1,183 @@ +#pragma once + +#include +#include "sdkconfig.h" + +#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565 +#define IMAGE_T uint16_t +#define COLOR_RED 0b0000000011111000 +#define COLOR_GREEN 0b1110000000000111 +#define COLOR_BLUE 0b0001111100000000 +#else +#define IMAGE_T uint8_t +#define COLOR_RED 0x0000FF +#define COLOR_GREEN 0x00FF00 +#define COLOR_BLUE 0xFF0000 +#endif + +#if CONFIG_CAMERA_MODULE_WROVER_KIT +#define CAMERA_MODULE_NAME "Wrover Kit" +#define CAMERA_PIN_PWDN -1 +#define CAMERA_PIN_RESET -1 +#define CAMERA_PIN_XCLK 21 +#define CAMERA_PIN_SIOD 26 +#define CAMERA_PIN_SIOC 27 + +#define CAMERA_PIN_D7 35 +#define CAMERA_PIN_D6 34 +#define CAMERA_PIN_D5 39 +#define CAMERA_PIN_D4 36 +#define CAMERA_PIN_D3 19 +#define CAMERA_PIN_D2 18 +#define CAMERA_PIN_D1 5 +#define CAMERA_PIN_D0 4 +#define CAMERA_PIN_VSYNC 25 +#define CAMERA_PIN_HREF 23 +#define CAMERA_PIN_PCLK 22 + +#elif CONFIG_CAMERA_MODULE_ESP_EYE +#define CAMERA_MODULE_NAME "ESP-EYE" +#define CAMERA_PIN_PWDN -1 +#define CAMERA_PIN_RESET -1 +#define CAMERA_PIN_XCLK 4 +#define CAMERA_PIN_SIOD 18 +#define CAMERA_PIN_SIOC 23 + +#define CAMERA_PIN_D7 36 +#define CAMERA_PIN_D6 37 +#define CAMERA_PIN_D5 38 +#define CAMERA_PIN_D4 39 +#define CAMERA_PIN_D3 35 +#define CAMERA_PIN_D2 14 +#define CAMERA_PIN_D1 13 +#define CAMERA_PIN_D0 34 +#define CAMERA_PIN_VSYNC 5 +#define CAMERA_PIN_HREF 27 +#define CAMERA_PIN_PCLK 25 + +#elif CONFIG_CAMERA_MODULE_ESP_S3_EYE +#define CAMERA_MODULE_NAME "ESP-S3-EYE" +#define CAMERA_PIN_PWDN 43 +#define CAMERA_PIN_RESET 44 + +#define CAMERA_PIN_VSYNC 6 +#define CAMERA_PIN_HREF 7 +#define CAMERA_PIN_PCLK 13 +#define CAMERA_PIN_XCLK 15 + +#define CAMERA_PIN_SIOD 4 +#define CAMERA_PIN_SIOC 5 + +#define CAMERA_PIN_D0 11 +#define CAMERA_PIN_D1 9 +#define CAMERA_PIN_D2 8 +#define CAMERA_PIN_D3 10 +#define CAMERA_PIN_D4 12 +#define CAMERA_PIN_D5 18 +#define CAMERA_PIN_D6 17 +#define CAMERA_PIN_D7 16 + +#elif CONFIG_CAMERA_MODEL_ESP32_CAM_BOARD +#define CAMERA_MODULE_NAME "ESP-DEVCAM" +#define CAMERA_PIN_PWDN 32 +#define CAMERA_PIN_RESET 33 + +#define CAMERA_PIN_XCLK 4 +#define CAMERA_PIN_SIOD 18 +#define CAMERA_PIN_SIOC 23 + +#define CAMERA_PIN_D7 36 +#define CAMERA_PIN_D6 19 +#define CAMERA_PIN_D5 21 +#define CAMERA_PIN_D4 39 +#define CAMERA_PIN_D3 35 +#define CAMERA_PIN_D2 14 +#define CAMERA_PIN_D1 13 +#define CAMERA_PIN_D0 34 +#define CAMERA_PIN_VSYNC 5 +#define CAMERA_PIN_HREF 27 +#define CAMERA_PIN_PCLK 25 + +#elif CONFIG_CAMERA_MODULE_M5STACK_PSRAM +#define CAMERA_MODULE_NAME "M5STACK-PSRAM" +#define CAMERA_PIN_PWDN -1 +#define CAMERA_PIN_RESET 15 + +#define CAMERA_PIN_XCLK 27 +#define CAMERA_PIN_SIOD 25 +#define CAMERA_PIN_SIOC 23 + +#define CAMERA_PIN_D7 19 +#define CAMERA_PIN_D6 36 +#define CAMERA_PIN_D5 18 +#define CAMERA_PIN_D4 39 +#define CAMERA_PIN_D3 5 +#define CAMERA_PIN_D2 34 +#define CAMERA_PIN_D1 35 +#define CAMERA_PIN_D0 32 +#define CAMERA_PIN_VSYNC 22 +#define CAMERA_PIN_HREF 26 +#define CAMERA_PIN_PCLK 21 + +#elif CONFIG_CAMERA_MODULE_M5STACK_WIDE +#define CAMERA_MODULE_NAME "M5STACK-WIDE" +#define CAMERA_PIN_PWDN -1 +#define CAMERA_PIN_RESET 15 +#define CAMERA_PIN_XCLK 27 +#define CAMERA_PIN_SIOD 22 +#define CAMERA_PIN_SIOC 23 + +#define CAMERA_PIN_D7 19 +#define CAMERA_PIN_D6 36 +#define CAMERA_PIN_D5 18 +#define CAMERA_PIN_D4 39 +#define CAMERA_PIN_D3 5 +#define CAMERA_PIN_D2 34 +#define CAMERA_PIN_D1 35 +#define CAMERA_PIN_D0 32 +#define CAMERA_PIN_VSYNC 25 +#define CAMERA_PIN_HREF 26 +#define CAMERA_PIN_PCLK 21 + +#elif CONFIG_CAMERA_MODULE_AI_THINKER +#define CAMERA_MODULE_NAME "AI-THINKER" +#define CAMERA_PIN_PWDN 32 +#define CAMERA_PIN_RESET -1 +#define CAMERA_PIN_XCLK 0 +#define CAMERA_PIN_SIOD 26 +#define CAMERA_PIN_SIOC 27 + +#define CAMERA_PIN_D7 35 +#define CAMERA_PIN_D6 34 +#define CAMERA_PIN_D5 39 +#define CAMERA_PIN_D4 36 +#define CAMERA_PIN_D3 21 +#define CAMERA_PIN_D2 19 +#define CAMERA_PIN_D1 18 +#define CAMERA_PIN_D0 5 +#define CAMERA_PIN_VSYNC 25 +#define CAMERA_PIN_HREF 23 +#define CAMERA_PIN_PCLK 22 + +#elif CONFIG_CAMERA_MODULE_CUSTOM +#define CAMERA_MODULE_NAME "CUSTOM" +#define CAMERA_PIN_PWDN CONFIG_CAMERA_PIN_PWDN +#define CAMERA_PIN_RESET CONFIG_CAMERA_PIN_RESET +#define CAMERA_PIN_XCLK CONFIG_CAMERA_PIN_XCLK +#define CAMERA_PIN_SIOD CONFIG_CAMERA_PIN_SIOD +#define CAMERA_PIN_SIOC CONFIG_CAMERA_PIN_SIOC + +#define CAMERA_PIN_D7 CONFIG_CAMERA_PIN_Y9 +#define CAMERA_PIN_D6 CONFIG_CAMERA_PIN_Y8 +#define CAMERA_PIN_D5 CONFIG_CAMERA_PIN_Y7 +#define CAMERA_PIN_D4 CONFIG_CAMERA_PIN_Y6 +#define CAMERA_PIN_D3 CONFIG_CAMERA_PIN_Y5 +#define CAMERA_PIN_D2 CONFIG_CAMERA_PIN_Y4 +#define CAMERA_PIN_D1 CONFIG_CAMERA_PIN_Y3 +#define CAMERA_PIN_D0 CONFIG_CAMERA_PIN_Y2 +#define CAMERA_PIN_VSYNC CONFIG_CAMERA_PIN_VSYNC +#define CAMERA_PIN_HREF CONFIG_CAMERA_PIN_HREF +#define CAMERA_PIN_PCLK CONFIG_CAMERA_PIN_PCLK +#endif + +#define XCLK_FREQ_HZ 20000000 diff --git a/components/common/include/app_lcd.h b/components/common/include/app_lcd.h new file mode 100644 index 0000000..e69de29 diff --git a/components/common/include/app_led.h b/components/common/include/app_led.h new file mode 100644 index 0000000..31efc5a --- /dev/null +++ b/components/common/include/app_led.h @@ -0,0 +1,15 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if CONFIG_LED_ILLUMINATOR_ENABLED + void app_led_init(); + void app_led_duty(int duty) +#endif + +#ifdef __cplusplus +} +#endif