2021-09-27 15:24:28 +08:00
|
|
|
#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<dl::detect::result_t> &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;
|
|
|
|
|
2021-10-26 17:03:29 +08:00
|
|
|
xTaskCreatePinnedToCore(task_process_handler, "cat_face_process", 3 * 1024, NULL, 5, NULL, 1);
|
2021-09-27 15:24:28 +08:00
|
|
|
if (xQueueEvent)
|
|
|
|
xTaskCreatePinnedToCore(task_event_handler, "cat_face_event", 1 * 1024, NULL, 5, NULL, 1);
|
|
|
|
}
|