28
28
static const char *TAG = " camera_httpd" ;
29
29
#endif
30
30
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
32
32
#ifdef BOARD_HAS_PSRAM
33
33
#define CONFIG_ESP_FACE_DETECT_ENABLED 1
34
34
// 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)
148
148
return filter;
149
149
}
150
150
151
+ /* unused function triggers error
151
152
static int ra_filter_run(ra_filter_t *filter, int value)
152
153
{
153
154
if (!filter->values)
@@ -165,6 +166,7 @@ static int ra_filter_run(ra_filter_t *filter, int value)
165
166
}
166
167
return filter->sum / filter->count;
167
168
}
169
+ */
168
170
169
171
#if CONFIG_ESP_FACE_DETECT_ENABLED
170
172
#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
@@ -294,7 +296,9 @@ static esp_err_t bmp_handler(httpd_req_t *req)
294
296
{
295
297
camera_fb_t *fb = NULL ;
296
298
esp_err_t res = ESP_OK;
299
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
297
300
uint64_t fr_start = esp_timer_get_time ();
301
+ #endif
298
302
fb = esp_camera_fb_get ();
299
303
if (!fb)
300
304
{
@@ -323,7 +327,9 @@ static esp_err_t bmp_handler(httpd_req_t *req)
323
327
}
324
328
res = httpd_resp_send (req, (const char *)buf, buf_len);
325
329
free (buf);
330
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
326
331
uint64_t fr_end = esp_timer_get_time ();
332
+ #endif
327
333
ESP_LOGI (TAG, " BMP: %llums, %uB" , (uint64_t )((fr_end - fr_start) / 1000 ), buf_len);
328
334
return res;
329
335
}
@@ -347,7 +353,9 @@ static esp_err_t capture_handler(httpd_req_t *req)
347
353
{
348
354
camera_fb_t *fb = NULL ;
349
355
esp_err_t res = ESP_OK;
356
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
350
357
int64_t fr_start = esp_timer_get_time ();
358
+ #endif
351
359
352
360
#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
353
361
enable_led (true );
@@ -377,26 +385,36 @@ static esp_err_t capture_handler(httpd_req_t *req)
377
385
size_t out_len, out_width, out_height;
378
386
uint8_t *out_buf;
379
387
bool s;
388
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
380
389
bool detected = false ;
390
+ #endif
381
391
int face_id = 0 ;
382
392
if (!detection_enabled || fb->width > 400 )
383
393
{
384
394
#endif
395
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
385
396
size_t fb_len = 0 ;
397
+ #endif
386
398
if (fb->format == PIXFORMAT_JPEG)
387
399
{
400
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
388
401
fb_len = fb->len ;
402
+ #endif
389
403
res = httpd_resp_send (req, (const char *)fb->buf , fb->len );
390
404
}
391
405
else
392
406
{
393
407
jpg_chunking_t jchunk = {req, 0 };
394
408
res = frame2jpg_cb (fb, 80 , jpg_encode_stream, &jchunk) ? ESP_OK : ESP_FAIL;
395
409
httpd_resp_send_chunk (req, NULL , 0 );
410
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
396
411
fb_len = jchunk.len ;
412
+ #endif
397
413
}
398
414
esp_camera_fb_return (fb);
415
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
399
416
int64_t fr_end = esp_timer_get_time ();
417
+ #endif
400
418
ESP_LOGI (TAG, " JPG: %uB %ums" , (uint32_t )(fb_len), (uint32_t )((fr_end - fr_start) / 1000 ));
401
419
return res;
402
420
#if CONFIG_ESP_FACE_DETECT_ENABLED
@@ -425,12 +443,14 @@ static esp_err_t capture_handler(httpd_req_t *req)
425
443
rfb.data = fb->buf ;
426
444
rfb.bytes_per_pixel = 2 ;
427
445
rfb.format = FB_RGB565;
446
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
428
447
detected = true ;
448
+ #endif
429
449
draw_face_boxes (&rfb, &results, face_id);
430
450
}
431
451
s = fmt2jpg_cb (fb->buf , fb->len , fb->width , fb->height , PIXFORMAT_RGB565, 90 , jpg_encode_stream, &jchunk);
432
452
esp_camera_fb_return (fb);
433
- } else
453
+ } else
434
454
{
435
455
out_len = fb->width * fb->height * 3 ;
436
456
out_width = fb->width ;
@@ -468,7 +488,9 @@ static esp_err_t capture_handler(httpd_req_t *req)
468
488
#endif
469
489
470
490
if (results.size () > 0 ) {
491
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
471
492
detected = true ;
493
+ #endif
472
494
#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
473
495
if (recognition_enabled) {
474
496
face_id = run_face_recognition (&rfb, &results);
@@ -486,8 +508,9 @@ static esp_err_t capture_handler(httpd_req_t *req)
486
508
httpd_resp_send_500 (req);
487
509
return ESP_FAIL;
488
510
}
489
-
511
+ # if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
490
512
int64_t fr_end = esp_timer_get_time ();
513
+ #endif
491
514
ESP_LOGI (TAG, " FACE: %uB %ums %s%d" , (uint32_t )(jchunk.len ), (uint32_t )((fr_end - fr_start) / 1000 ), detected ? " DETECTED " : " " , face_id);
492
515
return res;
493
516
#endif
@@ -502,14 +525,15 @@ static esp_err_t stream_handler(httpd_req_t *req)
502
525
uint8_t *_jpg_buf = NULL ;
503
526
char *part_buf[128 ];
504
527
#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
506
536
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
-
513
537
size_t out_len = 0 , out_width = 0 , out_height = 0 ;
514
538
uint8_t *out_buf = NULL ;
515
539
bool s = false ;
@@ -544,7 +568,9 @@ static esp_err_t stream_handler(httpd_req_t *req)
544
568
while (true )
545
569
{
546
570
#if CONFIG_ESP_FACE_DETECT_ENABLED
571
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
547
572
detected = false ;
573
+ #endif
548
574
face_id = 0 ;
549
575
#endif
550
576
@@ -559,11 +585,13 @@ static esp_err_t stream_handler(httpd_req_t *req)
559
585
_timestamp.tv_sec = fb->timestamp .tv_sec ;
560
586
_timestamp.tv_usec = fb->timestamp .tv_usec ;
561
587
#if CONFIG_ESP_FACE_DETECT_ENABLED
588
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
562
589
fr_start = esp_timer_get_time ();
563
590
fr_ready = fr_start;
564
- fr_face = fr_start;
565
591
fr_encode = fr_start;
566
592
fr_recognize = fr_start;
593
+ fr_face = fr_start;
594
+ #endif
567
595
if (!detection_enabled || fb->width > 400 )
568
596
{
569
597
#endif
@@ -592,23 +620,29 @@ static esp_err_t stream_handler(httpd_req_t *req)
592
620
&& !recognition_enabled
593
621
#endif
594
622
){
623
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
595
624
fr_ready = esp_timer_get_time ();
625
+ #endif
596
626
#if TWO_STAGE
597
627
std::list<dl::detect::result_t > &candidates = s1.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 });
598
628
std::list<dl::detect::result_t > &results = s2.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 }, candidates);
599
629
#else
600
630
std::list<dl::detect::result_t > &results = s1.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 });
601
631
#endif
632
+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
602
633
fr_face = esp_timer_get_time ();
603
634
fr_recognize = fr_face;
635
+ #endif
604
636
if (results.size () > 0 ) {
605
637
fb_data_t rfb;
606
638
rfb.width = fb->width ;
607
639
rfb.height = fb->height ;
608
640
rfb.data = fb->buf ;
609
641
rfb.bytes_per_pixel = 2 ;
610
642
rfb.format = FB_RGB565;
643
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
611
644
detected = true ;
645
+ #endif
612
646
draw_face_boxes (&rfb, &results, face_id);
613
647
}
614
648
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)
618
652
ESP_LOGE (TAG, " fmt2jpg failed" );
619
653
res = ESP_FAIL;
620
654
}
655
+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
621
656
fr_encode = esp_timer_get_time ();
622
- } else
657
+ #endif
658
+ } else
623
659
{
624
660
out_len = fb->width * fb->height * 3 ;
625
661
out_width = fb->width ;
@@ -637,7 +673,9 @@ static esp_err_t stream_handler(httpd_req_t *req)
637
673
ESP_LOGE (TAG, " to rgb888 failed" );
638
674
res = ESP_FAIL;
639
675
} else {
676
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
640
677
fr_ready = esp_timer_get_time ();
678
+ #endif
641
679
642
680
fb_data_t rfb;
643
681
rfb.width = out_width;
@@ -653,15 +691,21 @@ static esp_err_t stream_handler(httpd_req_t *req)
653
691
std::list<dl::detect::result_t > &results = s1.infer ((uint8_t *)out_buf, {(int )out_height, (int )out_width, 3 });
654
692
#endif
655
693
694
+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
656
695
fr_face = esp_timer_get_time ();
657
696
fr_recognize = fr_face;
697
+ #endif
658
698
659
699
if (results.size () > 0 ) {
700
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
660
701
detected = true ;
702
+ #endif
661
703
#if CONFIG_ESP_FACE_RECOGNITION_ENABLED
662
704
if (recognition_enabled) {
663
705
face_id = run_face_recognition (&rfb, &results);
706
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
664
707
fr_recognize = esp_timer_get_time ();
708
+ #endif
665
709
}
666
710
#endif
667
711
draw_face_boxes (&rfb, &results, face_id);
@@ -672,7 +716,9 @@ static esp_err_t stream_handler(httpd_req_t *req)
672
716
ESP_LOGE (TAG, " fmt2jpg failed" );
673
717
res = ESP_FAIL;
674
718
}
719
+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
675
720
fr_encode = esp_timer_get_time ();
721
+ #endif
676
722
}
677
723
}
678
724
}
@@ -710,7 +756,7 @@ static esp_err_t stream_handler(httpd_req_t *req)
710
756
}
711
757
int64_t fr_end = esp_timer_get_time ();
712
758
713
- #if CONFIG_ESP_FACE_DETECT_ENABLED
759
+ #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
714
760
int64_t ready_time = (fr_ready - fr_start) / 1000 ;
715
761
int64_t face_time = (fr_face - fr_ready) / 1000 ;
716
762
int64_t recognize_time = (fr_recognize - fr_face) / 1000 ;
@@ -719,9 +765,10 @@ static esp_err_t stream_handler(httpd_req_t *req)
719
765
#endif
720
766
721
767
int64_t frame_time = fr_end - last_frame;
722
- last_frame = fr_end;
723
768
frame_time /= 1000 ;
769
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
724
770
uint32_t avg_frame_time = ra_filter_run (&ra_filter, frame_time);
771
+ #endif
725
772
ESP_LOGI (TAG, " MJPG: %uB %ums (%.1ffps), AVG: %ums (%.1ffps)"
726
773
#if CONFIG_ESP_FACE_DETECT_ENABLED
727
774
" , %u+%u+%u+%u=%u %s%d"
@@ -743,7 +790,6 @@ static esp_err_t stream_handler(httpd_req_t *req)
743
790
enable_led (false );
744
791
#endif
745
792
746
- last_frame = 0 ;
747
793
return res;
748
794
}
749
795
0 commit comments