From 4cc21d496be5946cb159fb918a7617c117907260 Mon Sep 17 00:00:00 2001 From: Ye Hang Yang Date: Mon, 27 Sep 2021 15:24:28 +0800 Subject: [PATCH] :sparkles: cat_face_detection module --- .../modules/ai/who_cat_face_detection.cpp | 86 +++++++++++++++++++ .../modules/ai/who_cat_face_detection.hpp | 7 +- 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/components/modules/ai/who_cat_face_detection.cpp b/components/modules/ai/who_cat_face_detection.cpp index e69de29..1ce082d 100644 --- a/components/modules/ai/who_cat_face_detection.cpp +++ b/components/modules/ai/who_cat_face_detection.cpp @@ -0,0 +1,86 @@ +#include "who_cat_face_detection.hpp" + +#include "esp_log.h" +#include "esp_camera.h" + +#include "dl_image.hpp" +#include "cat_face_detect_mn03.hpp" + +#include "who_ai_utils.hpp" + +static const char *TAG = "cat_face_detection"; + +static QueueHandle_t xQueueFrameI = NULL; +static QueueHandle_t xQueueEvent = NULL; +static QueueHandle_t xQueueFrameO = NULL; +static QueueHandle_t xQueueResult = NULL; + +static bool gEvent = true; +static bool gReturnFB = true; + +static void task_process_handler(void *arg) +{ + camera_fb_t *frame = NULL; + CatFaceDetectMN03 detector(0.4F, 0.3F, 10, 0.3F); + + while (true) + { + if (gEvent) + { + bool is_detected = false; + if (xQueueReceive(xQueueFrameI, &frame, portMAX_DELAY)) + { + std::list &detect_results = detector.infer((uint16_t *)frame->buf, {(int)frame->height, (int)frame->width, 3}); + if (detect_results.size() > 0) + { + draw_detection_result((uint16_t *)frame->buf, frame->height, frame->width, detect_results); + print_detection_result(detect_results); + is_detected = true; + } + } + + if (xQueueFrameO) + { + xQueueSend(xQueueFrameO, &frame, portMAX_DELAY); + } + else if (gReturnFB) + { + esp_camera_fb_return(frame); + } + else + { + free(frame); + } + + if (xQueueResult) + { + xQueueSend(xQueueResult, &is_detected, portMAX_DELAY); + } + } + } +} + +static void task_event_handler(void *arg) +{ + while (true) + { + xQueueReceive(xQueueEvent, &(gEvent), portMAX_DELAY); + } +} + +void register_cat_face_detection(const QueueHandle_t frame_i, + const QueueHandle_t event, + const QueueHandle_t result, + const QueueHandle_t frame_o, + const bool camera_fb_return) +{ + xQueueFrameI = frame_i; + xQueueFrameO = frame_o; + xQueueEvent = event; + xQueueResult = result; + gReturnFB = camera_fb_return; + + xTaskCreatePinnedToCore(task_process_handler, "cat_face_process", 2 * 1024, NULL, 5, NULL, 1); + if (xQueueEvent) + xTaskCreatePinnedToCore(task_event_handler, "cat_face_event", 1 * 1024, NULL, 5, NULL, 1); +} diff --git a/components/modules/ai/who_cat_face_detection.hpp b/components/modules/ai/who_cat_face_detection.hpp index 9da6717..0fcded6 100644 --- a/components/modules/ai/who_cat_face_detection.hpp +++ b/components/modules/ai/who_cat_face_detection.hpp @@ -5,5 +5,8 @@ #include "freertos/task.h" #include "freertos/semphr.h" -void register_cat_face_detection(QueueHandle_t frame_i, QueueHandle_t event, - QueueHandle_t result, QueueHandle_t frame_o = NULL); +void register_cat_face_detection(QueueHandle_t frame_i, + QueueHandle_t event, + QueueHandle_t result, + QueueHandle_t frame_o, + const bool camera_fb_return);