2828static const char *TAG = " camera_httpd" ;
2929#endif
3030
31- // Face Detection will not work on boards without (or with disabled) PSRAM
31+ // Face Detection will not work on boards without (or with disabled) PSRAM
3232#ifdef BOARD_HAS_PSRAM
3333#define CONFIG_ESP_FACE_DETECT_ENABLED 1
3434// Face Recognition takes upward from 15 seconds per frame on chips other than ESP32S3
@@ -148,6 +148,7 @@ static ra_filter_t *ra_filter_init(ra_filter_t *filter, size_t sample_size)
148148 return filter;
149149}
150150
151+ /* unused function triggers error
151152static int ra_filter_run(ra_filter_t *filter, int value)
152153{
153154 if (!filter->values)
@@ -165,6 +166,7 @@ static int ra_filter_run(ra_filter_t *filter, int value)
165166 }
166167 return filter->sum / filter->count;
167168}
169+ */
168170
169171#if CONFIG_ESP_FACE_DETECT_ENABLED
170172#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
@@ -294,7 +296,9 @@ static esp_err_t bmp_handler(httpd_req_t *req)
294296{
295297 camera_fb_t *fb = NULL ;
296298 esp_err_t res = ESP_OK;
299+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
297300 uint64_t fr_start = esp_timer_get_time ();
301+ #endif
298302 fb = esp_camera_fb_get ();
299303 if (!fb)
300304 {
@@ -323,7 +327,9 @@ static esp_err_t bmp_handler(httpd_req_t *req)
323327 }
324328 res = httpd_resp_send (req, (const char *)buf, buf_len);
325329 free (buf);
330+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
326331 uint64_t fr_end = esp_timer_get_time ();
332+ #endif
327333 ESP_LOGI (TAG, " BMP: %llums, %uB" , (uint64_t )((fr_end - fr_start) / 1000 ), buf_len);
328334 return res;
329335}
@@ -347,7 +353,9 @@ static esp_err_t capture_handler(httpd_req_t *req)
347353{
348354 camera_fb_t *fb = NULL ;
349355 esp_err_t res = ESP_OK;
356+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
350357 int64_t fr_start = esp_timer_get_time ();
358+ #endif
351359
352360#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
353361 enable_led (true );
@@ -377,26 +385,36 @@ static esp_err_t capture_handler(httpd_req_t *req)
377385 size_t out_len, out_width, out_height;
378386 uint8_t *out_buf;
379387 bool s;
388+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
380389 bool detected = false ;
390+ #endif
381391 int face_id = 0 ;
382392 if (!detection_enabled || fb->width > 400 )
383393 {
384394#endif
395+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
385396 size_t fb_len = 0 ;
397+ #endif
386398 if (fb->format == PIXFORMAT_JPEG)
387399 {
400+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
388401 fb_len = fb->len ;
402+ #endif
389403 res = httpd_resp_send (req, (const char *)fb->buf , fb->len );
390404 }
391405 else
392406 {
393407 jpg_chunking_t jchunk = {req, 0 };
394408 res = frame2jpg_cb (fb, 80 , jpg_encode_stream, &jchunk) ? ESP_OK : ESP_FAIL;
395409 httpd_resp_send_chunk (req, NULL , 0 );
410+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
396411 fb_len = jchunk.len ;
412+ #endif
397413 }
398414 esp_camera_fb_return (fb);
415+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
399416 int64_t fr_end = esp_timer_get_time ();
417+ #endif
400418 ESP_LOGI (TAG, " JPG: %uB %ums" , (uint32_t )(fb_len), (uint32_t )((fr_end - fr_start) / 1000 ));
401419 return res;
402420#if CONFIG_ESP_FACE_DETECT_ENABLED
@@ -425,12 +443,14 @@ static esp_err_t capture_handler(httpd_req_t *req)
425443 rfb.data = fb->buf ;
426444 rfb.bytes_per_pixel = 2 ;
427445 rfb.format = FB_RGB565;
446+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
428447 detected = true ;
448+ #endif
429449 draw_face_boxes (&rfb, &results, face_id);
430450 }
431451 s = fmt2jpg_cb (fb->buf , fb->len , fb->width , fb->height , PIXFORMAT_RGB565, 90 , jpg_encode_stream, &jchunk);
432452 esp_camera_fb_return (fb);
433- } else
453+ } else
434454 {
435455 out_len = fb->width * fb->height * 3 ;
436456 out_width = fb->width ;
@@ -468,7 +488,9 @@ static esp_err_t capture_handler(httpd_req_t *req)
468488#endif
469489
470490 if (results.size () > 0 ) {
491+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
471492 detected = true ;
493+ #endif
472494#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
473495 if (recognition_enabled) {
474496 face_id = run_face_recognition (&rfb, &results);
@@ -486,8 +508,9 @@ static esp_err_t capture_handler(httpd_req_t *req)
486508 httpd_resp_send_500 (req);
487509 return ESP_FAIL;
488510 }
489-
511+ # if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
490512 int64_t fr_end = esp_timer_get_time ();
513+ #endif
491514 ESP_LOGI (TAG, " FACE: %uB %ums %s%d" , (uint32_t )(jchunk.len ), (uint32_t )((fr_end - fr_start) / 1000 ), detected ? " DETECTED " : " " , face_id);
492515 return res;
493516#endif
@@ -502,14 +525,15 @@ static esp_err_t stream_handler(httpd_req_t *req)
502525 uint8_t *_jpg_buf = NULL ;
503526 char *part_buf[128 ];
504527#if CONFIG_ESP_FACE_DETECT_ENABLED
505- bool detected = false ;
528+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
529+ bool detected = false ;
530+ int64_t fr_ready = 0 ;
531+ int64_t fr_recognize = 0 ;
532+ int64_t fr_encode = 0 ;
533+ int64_t fr_face = 0 ;
534+ int64_t fr_start = 0 ;
535+ #endif
506536 int face_id = 0 ;
507- int64_t fr_start = 0 ;
508- int64_t fr_ready = 0 ;
509- int64_t fr_face = 0 ;
510- int64_t fr_recognize = 0 ;
511- int64_t fr_encode = 0 ;
512-
513537 size_t out_len = 0 , out_width = 0 , out_height = 0 ;
514538 uint8_t *out_buf = NULL ;
515539 bool s = false ;
@@ -544,7 +568,9 @@ static esp_err_t stream_handler(httpd_req_t *req)
544568 while (true )
545569 {
546570#if CONFIG_ESP_FACE_DETECT_ENABLED
571+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
547572 detected = false ;
573+ #endif
548574 face_id = 0 ;
549575#endif
550576
@@ -559,11 +585,13 @@ static esp_err_t stream_handler(httpd_req_t *req)
559585 _timestamp.tv_sec = fb->timestamp .tv_sec ;
560586 _timestamp.tv_usec = fb->timestamp .tv_usec ;
561587#if CONFIG_ESP_FACE_DETECT_ENABLED
588+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
562589 fr_start = esp_timer_get_time ();
563590 fr_ready = fr_start;
564- fr_face = fr_start;
565591 fr_encode = fr_start;
566592 fr_recognize = fr_start;
593+ fr_face = fr_start;
594+ #endif
567595 if (!detection_enabled || fb->width > 400 )
568596 {
569597#endif
@@ -592,23 +620,29 @@ static esp_err_t stream_handler(httpd_req_t *req)
592620 && !recognition_enabled
593621#endif
594622 ){
623+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
595624 fr_ready = esp_timer_get_time ();
625+ #endif
596626#if TWO_STAGE
597627 std::list<dl::detect::result_t > &candidates = s1.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 });
598628 std::list<dl::detect::result_t > &results = s2.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 }, candidates);
599629#else
600630 std::list<dl::detect::result_t > &results = s1.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 });
601631#endif
632+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
602633 fr_face = esp_timer_get_time ();
603634 fr_recognize = fr_face;
635+ #endif
604636 if (results.size () > 0 ) {
605637 fb_data_t rfb;
606638 rfb.width = fb->width ;
607639 rfb.height = fb->height ;
608640 rfb.data = fb->buf ;
609641 rfb.bytes_per_pixel = 2 ;
610642 rfb.format = FB_RGB565;
643+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
611644 detected = true ;
645+ #endif
612646 draw_face_boxes (&rfb, &results, face_id);
613647 }
614648 s = fmt2jpg (fb->buf , fb->len , fb->width , fb->height , PIXFORMAT_RGB565, 80 , &_jpg_buf, &_jpg_buf_len);
@@ -618,8 +652,10 @@ static esp_err_t stream_handler(httpd_req_t *req)
618652 ESP_LOGE (TAG, " fmt2jpg failed" );
619653 res = ESP_FAIL;
620654 }
655+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
621656 fr_encode = esp_timer_get_time ();
622- } else
657+ #endif
658+ } else
623659 {
624660 out_len = fb->width * fb->height * 3 ;
625661 out_width = fb->width ;
@@ -637,7 +673,9 @@ static esp_err_t stream_handler(httpd_req_t *req)
637673 ESP_LOGE (TAG, " to rgb888 failed" );
638674 res = ESP_FAIL;
639675 } else {
676+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
640677 fr_ready = esp_timer_get_time ();
678+ #endif
641679
642680 fb_data_t rfb;
643681 rfb.width = out_width;
@@ -653,15 +691,21 @@ static esp_err_t stream_handler(httpd_req_t *req)
653691 std::list<dl::detect::result_t > &results = s1.infer ((uint8_t *)out_buf, {(int )out_height, (int )out_width, 3 });
654692#endif
655693
694+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
656695 fr_face = esp_timer_get_time ();
657696 fr_recognize = fr_face;
697+ #endif
658698
659699 if (results.size () > 0 ) {
700+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
660701 detected = true ;
702+ #endif
661703#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
662704 if (recognition_enabled) {
663705 face_id = run_face_recognition (&rfb, &results);
706+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
664707 fr_recognize = esp_timer_get_time ();
708+ #endif
665709 }
666710#endif
667711 draw_face_boxes (&rfb, &results, face_id);
@@ -672,7 +716,9 @@ static esp_err_t stream_handler(httpd_req_t *req)
672716 ESP_LOGE (TAG, " fmt2jpg failed" );
673717 res = ESP_FAIL;
674718 }
719+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
675720 fr_encode = esp_timer_get_time ();
721+ #endif
676722 }
677723 }
678724 }
@@ -710,7 +756,7 @@ static esp_err_t stream_handler(httpd_req_t *req)
710756 }
711757 int64_t fr_end = esp_timer_get_time ();
712758
713- #if CONFIG_ESP_FACE_DETECT_ENABLED
759+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
714760 int64_t ready_time = (fr_ready - fr_start) / 1000 ;
715761 int64_t face_time = (fr_face - fr_ready) / 1000 ;
716762 int64_t recognize_time = (fr_recognize - fr_face) / 1000 ;
@@ -719,9 +765,10 @@ static esp_err_t stream_handler(httpd_req_t *req)
719765#endif
720766
721767 int64_t frame_time = fr_end - last_frame;
722- last_frame = fr_end;
723768 frame_time /= 1000 ;
769+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
724770 uint32_t avg_frame_time = ra_filter_run (&ra_filter, frame_time);
771+ #endif
725772 ESP_LOGI (TAG, " MJPG: %uB %ums (%.1ffps), AVG: %ums (%.1ffps)"
726773#if CONFIG_ESP_FACE_DETECT_ENABLED
727774 " , %u+%u+%u+%u=%u %s%d"
@@ -743,7 +790,6 @@ static esp_err_t stream_handler(httpd_req_t *req)
743790 enable_led (false );
744791#endif
745792
746- last_frame = 0 ;
747793 return res;
748794}
749795
0 commit comments