🔥 remove #if CONFIG_CAMERA_PIXEL_FORMAT_RGB565
parent
945643dba9
commit
ff38ec859f
|
@ -33,8 +33,6 @@ static const char *TAG = "app_dl";
|
||||||
|
|
||||||
void task_dl(void *arg)
|
void task_dl(void *arg)
|
||||||
{
|
{
|
||||||
camera_fb_t *fb = NULL;
|
|
||||||
IMAGE_T *image_ptr;
|
|
||||||
dl::tool::Latency latency_total(24);
|
dl::tool::Latency latency_total(24);
|
||||||
dl::tool::Latency latency_fetch;
|
dl::tool::Latency latency_fetch;
|
||||||
dl::tool::Latency latency_decode;
|
dl::tool::Latency latency_decode;
|
||||||
|
@ -71,9 +69,8 @@ void task_dl(void *arg)
|
||||||
|
|
||||||
latency_total.start();
|
latency_total.start();
|
||||||
|
|
||||||
/* 2. Get one image with camera */
|
|
||||||
latency_fetch.start();
|
latency_fetch.start();
|
||||||
fb = esp_camera_fb_get();
|
camera_fb_t *fb = esp_camera_fb_get();
|
||||||
if (!fb)
|
if (!fb)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "Camera capture failed");
|
ESP_LOGE(TAG, "Camera capture failed");
|
||||||
|
@ -82,28 +79,28 @@ void task_dl(void *arg)
|
||||||
latency_fetch.end();
|
latency_fetch.end();
|
||||||
|
|
||||||
#if CONFIG_DL_ENABLED
|
#if CONFIG_DL_ENABLED
|
||||||
/* 3. Transform image to RGB */
|
|
||||||
latency_decode.start();
|
latency_decode.start();
|
||||||
int image_height = fb->height;
|
IMAGE_T *image_ptr = (IMAGE_T *)app_camera_decode(fb);
|
||||||
int image_width = fb->width;
|
if (!image_ptr)
|
||||||
if (app_camera_decode(fb, &image_ptr) == false)
|
|
||||||
{
|
{
|
||||||
esp_camera_fb_return(fb);
|
esp_camera_fb_return(fb);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#if !CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
int image_height = fb->height;
|
||||||
esp_camera_fb_return(fb);
|
int image_width = fb->width;
|
||||||
#endif
|
pixformat_t image_format = fb->format;
|
||||||
|
|
||||||
|
if (image_format != PIXFORMAT_RGB565)
|
||||||
|
esp_camera_fb_return(fb);
|
||||||
latency_decode.end();
|
latency_decode.end();
|
||||||
|
|
||||||
/* 4. Do deep-learning processing */
|
|
||||||
#if CONFIG_DL_HUMAN_FACE
|
#if CONFIG_DL_HUMAN_FACE
|
||||||
latency_detect.start();
|
latency_detect.start();
|
||||||
#if CONFIG_DL_HUMAN_FACE_DETECTION_S2_ENABLED
|
#if CONFIG_DL_HUMAN_FACE_DETECTION_S2_ENABLED
|
||||||
std::list<dl::detect::result_t> &detect_candidates = detector.infer((IMAGE_T *)image_ptr, {(int)image_height, (int)image_width, 3});
|
std::list<dl::detect::result_t> &detect_candidates = detector.infer(image_ptr, {(int)image_height, (int)image_width, 3});
|
||||||
std::list<dl::detect::result_t> &detect_results = detector2.infer((IMAGE_T *)image_ptr, {(int)image_height, (int)image_width, 3}, detect_candidates);
|
std::list<dl::detect::result_t> &detect_results = detector2.infer(image_ptr, {(int)image_height, (int)image_width, 3}, detect_candidates);
|
||||||
#else
|
#else
|
||||||
std::list<dl::detect::result_t> &detect_results = detector.infer((IMAGE_T *)image_ptr, {(int)image_height, (int)image_width, 3});
|
std::list<dl::detect::result_t> &detect_results = detector.infer(image_ptr, {(int)image_height, (int)image_width, 3});
|
||||||
#endif
|
#endif
|
||||||
latency_detect.end();
|
latency_detect.end();
|
||||||
|
|
||||||
|
@ -121,12 +118,11 @@ void task_dl(void *arg)
|
||||||
|
|
||||||
#if CONFIG_DL_CAT_FACE
|
#if CONFIG_DL_CAT_FACE
|
||||||
latency_detect.start();
|
latency_detect.start();
|
||||||
std::list<dl::detect::result_t> &detect_results = detector.infer((IMAGE_T *)image_ptr, {(int)image_height, (int)image_width, 3});
|
std::list<dl::detect::result_t> &detect_results = detector.infer(image_ptr, {(int)image_height, (int)image_width, 3});
|
||||||
latency_detect.end();
|
latency_detect.end();
|
||||||
if (detect_results.size() > 0)
|
if (detect_results.size() > 0)
|
||||||
{
|
{
|
||||||
is_detected = true;
|
print_detection_result(detect_results);
|
||||||
print_detection_result(image_ptr, fb->height, fb->width, detect_results);
|
|
||||||
}
|
}
|
||||||
#endif // CONFIG_DL_CAT_FACE
|
#endif // CONFIG_DL_CAT_FACE
|
||||||
|
|
||||||
|
@ -136,20 +132,19 @@ void task_dl(void *arg)
|
||||||
latency_detect.end();
|
latency_detect.end();
|
||||||
#endif // CONFIG_DL_HUMAN_HAND
|
#endif // CONFIG_DL_HUMAN_HAND
|
||||||
|
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
if (image_format == PIXFORMAT_RGB565)
|
||||||
esp_camera_fb_return(fb);
|
esp_camera_fb_return(fb);
|
||||||
#else
|
else
|
||||||
dl::tool::free_aligned(image_ptr);
|
free(image_ptr);
|
||||||
#endif
|
|
||||||
|
|
||||||
#else // not CONFIG_DL_ENABLED
|
#else
|
||||||
esp_camera_fb_return(fb);
|
esp_camera_fb_return(fb);
|
||||||
#endif // CONFIG_DL_ENABLED
|
#endif // CONFIG_DL_ENABLED
|
||||||
|
|
||||||
latency_total.end();
|
latency_total.end();
|
||||||
uint32_t frame_latency = latency_total.get_period() / 1000;
|
uint32_t frame_latency = latency_total.get_period() / 1000;
|
||||||
uint32_t average_frame_latency = latency_total.get_average_period() / 1000;
|
uint32_t average_frame_latency = latency_total.get_average_period() / 1000;
|
||||||
ESP_LOGI(TAG, "Frame: %4ums (%2.1ffps), Average: %4ums (%2.1ffps) | fetch: %4ums, decode: %4ums, detect: %4ums, recognize: %5ums",
|
ESP_LOGI("Frame Latency", "%4ums (%2.1ffps), Average: %4ums (%2.1ffps) | fetch: %4ums, decode: %4ums, detect: %4ums, recognize: %5ums",
|
||||||
frame_latency, 1000.0 / frame_latency, average_frame_latency, 1000.0 / average_frame_latency,
|
frame_latency, 1000.0 / frame_latency, average_frame_latency, 1000.0 / average_frame_latency,
|
||||||
latency_fetch.get_period() / 1000,
|
latency_fetch.get_period() / 1000,
|
||||||
latency_decode.get_period() / 1000,
|
latency_decode.get_period() / 1000,
|
||||||
|
|
|
@ -222,8 +222,10 @@ static esp_err_t stream_handler(httpd_req_t *req)
|
||||||
if (detection_enabled && fb->width < 400)
|
if (detection_enabled && fb->width < 400)
|
||||||
{
|
{
|
||||||
latency_decode.start();
|
latency_decode.start();
|
||||||
if (app_camera_decode(fb, &image_ptr) == false)
|
image_ptr = (IMAGE_T *)app_camera_decode(fb);
|
||||||
|
if (!image_ptr)
|
||||||
{
|
{
|
||||||
|
ESP_LOGE(TAG, "Frame decode failed");
|
||||||
res = ESP_FAIL;
|
res = ESP_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -232,17 +234,17 @@ static esp_err_t stream_handler(httpd_req_t *req)
|
||||||
#if CONFIG_DL_HUMAN_FACE
|
#if CONFIG_DL_HUMAN_FACE
|
||||||
latency_detect.start();
|
latency_detect.start();
|
||||||
#if CONFIG_DL_HUMAN_FACE_DETECTION_S2_ENABLED
|
#if CONFIG_DL_HUMAN_FACE_DETECTION_S2_ENABLED
|
||||||
std::list<dl::detect::result_t> &detect_candidates = detector.infer((IMAGE_T *)image_ptr, {(int)fb->height, (int)fb->width, 3});
|
std::list<dl::detect::result_t> &detect_candidates = detector.infer(image_ptr, {(int)fb->height, (int)fb->width, 3});
|
||||||
std::list<dl::detect::result_t> &detect_results = detector2.infer((IMAGE_T *)image_ptr, {(int)fb->height, (int)fb->width, 3}, detect_candidates);
|
std::list<dl::detect::result_t> &detect_results = detector2.infer(image_ptr, {(int)fb->height, (int)fb->width, 3}, detect_candidates);
|
||||||
#else
|
#else
|
||||||
std::list<dl::detect::result_t> &detect_results = detector.infer((IMAGE_T *)image_ptr, {(int)fb->height, (int)fb->width, 3});
|
std::list<dl::detect::result_t> &detect_results = detector.infer(image_ptr, {(int)fb->height, (int)fb->width, 3});
|
||||||
#endif
|
#endif
|
||||||
latency_detect.end();
|
latency_detect.end();
|
||||||
|
|
||||||
if (detect_results.size() > 0)
|
if (detect_results.size() > 0)
|
||||||
{
|
{
|
||||||
is_detected = true;
|
is_detected = true;
|
||||||
draw_detection_result((IMAGE_T*)image_ptr, fb->height, fb->width, detect_results);
|
draw_detection_result(image_ptr, fb->height, fb->width, detect_results);
|
||||||
|
|
||||||
latency_recognize.start();
|
latency_recognize.start();
|
||||||
if (recognition_enabled)
|
if (recognition_enabled)
|
||||||
|
@ -257,12 +259,12 @@ static esp_err_t stream_handler(httpd_req_t *req)
|
||||||
|
|
||||||
#if CONFIG_DL_CAT_FACE
|
#if CONFIG_DL_CAT_FACE
|
||||||
latency_detect.start();
|
latency_detect.start();
|
||||||
std::list<dl::detect::result_t> &detect_results = detector.infer((IMAGE_T *)image_ptr, {(int)fb->height, (int)fb->width, 3});
|
std::list<dl::detect::result_t> &detect_results = detector.infer(image_ptr, {(int)fb->height, (int)fb->width, 3});
|
||||||
latency_detect.end();
|
latency_detect.end();
|
||||||
if (detect_results.size() > 0)
|
if (detect_results.size() > 0)
|
||||||
{
|
{
|
||||||
is_detected = true;
|
is_detected = true;
|
||||||
draw_detection_result((IMAGE_T*)image_ptr, fb->height, fb->width, detect_results);
|
draw_detection_result(image_ptr, fb->height, fb->width, detect_results);
|
||||||
}
|
}
|
||||||
#endif // CONFIG_DL_CAT_FACE
|
#endif // CONFIG_DL_CAT_FACE
|
||||||
|
|
||||||
|
@ -277,17 +279,16 @@ static esp_err_t stream_handler(httpd_req_t *req)
|
||||||
latency_encode.start();
|
latency_encode.start();
|
||||||
if (is_detected)
|
if (is_detected)
|
||||||
{
|
{
|
||||||
#if CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
if (!fmt2jpg((uint8_t *)image_ptr, fb->width * fb->height * 3, fb->width, fb->height, CAMERA_PIXEL_FORMAT, 90, &_jpg_buf, &_jpg_buf_len))
|
||||||
if (!fmt2jpg((uint8_t *)image_ptr, fb->width * fb->height * 3, fb->width, fb->height, PIXFORMAT_RGB565, 90, &_jpg_buf, &_jpg_buf_len))
|
|
||||||
#else
|
|
||||||
if (!fmt2jpg((uint8_t *)image_ptr, fb->width * fb->height * 3, fb->width, fb->height, PIXFORMAT_RGB888, 90, &_jpg_buf, &_jpg_buf_len))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "fmt2jpg failed");
|
ESP_LOGE(TAG, "fmt2jpg failed");
|
||||||
res = ESP_FAIL;
|
res = ESP_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fb->format == PIXFORMAT_RGB565)
|
||||||
|
image_ptr = NULL;
|
||||||
|
|
||||||
esp_camera_fb_return(fb);
|
esp_camera_fb_return(fb);
|
||||||
fb = NULL;
|
fb = NULL;
|
||||||
}
|
}
|
||||||
|
@ -305,14 +306,16 @@ static esp_err_t stream_handler(httpd_req_t *req)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fb->format == PIXFORMAT_RGB565)
|
||||||
|
image_ptr = NULL;
|
||||||
|
|
||||||
esp_camera_fb_return(fb);
|
esp_camera_fb_return(fb);
|
||||||
fb = NULL;
|
fb = NULL;
|
||||||
}
|
}
|
||||||
|
if (image_ptr)
|
||||||
|
free(image_ptr);
|
||||||
latency_encode.end();
|
latency_encode.end();
|
||||||
|
|
||||||
#if !CONFIG_CAMERA_PIXEL_FORMAT_RGB565
|
|
||||||
dl::tool::free_aligned(image_ptr);
|
|
||||||
#endif
|
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
if (res == ESP_OK)
|
if (res == ESP_OK)
|
||||||
|
@ -352,7 +355,7 @@ static esp_err_t stream_handler(httpd_req_t *req)
|
||||||
uint32_t frame_latency = latency_total.get_period() / 1000;
|
uint32_t frame_latency = latency_total.get_period() / 1000;
|
||||||
uint32_t average_frame_latency = latency_total.get_average_period() / 1000;
|
uint32_t average_frame_latency = latency_total.get_average_period() / 1000;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Frame: %4ums (%2.1ffps), Average: %4ums (%2.1ffps) | fetch %4ums, decode: %4ums, detect: %4ums, recognize: %5ums, encode: %4ums",
|
ESP_LOGI("Frame Latency", "%4ums (%2.1ffps), Average: %4ums (%2.1ffps) | fetch %4ums, decode: %4ums, detect: %4ums, recognize: %5ums, encode: %4ums",
|
||||||
frame_latency, 1000.0 / frame_latency, average_frame_latency, 1000.0 / average_frame_latency,
|
frame_latency, 1000.0 / frame_latency, average_frame_latency, 1000.0 / average_frame_latency,
|
||||||
latency_fetch.get_period() / 1000,
|
latency_fetch.get_period() / 1000,
|
||||||
latency_decode.get_period() / 1000,
|
latency_decode.get_period() / 1000,
|
||||||
|
|
Loading…
Reference in New Issue