24
24
#include " esp32-hal-log.h"
25
25
#endif
26
26
27
- // Face Detection will not work on boards without (or with disabled) PSRAM
28
- #ifdef BOARD_HAS_PSRAM
29
- // Face Recognition takes upward from 15 seconds per frame on chips other than ESP32S3
30
- // Makes no sense to have it enabled for them
31
- #if CONFIG_IDF_TARGET_ESP32S3
32
- #define CONFIG_ESP_FACE_RECOGNITION_ENABLED 1
33
- #define CONFIG_ESP_FACE_DETECT_ENABLED 1
34
- #else
35
- #define CONFIG_ESP_FACE_RECOGNITION_ENABLED 0
36
- #define CONFIG_ESP_FACE_DETECT_ENABLED 0
37
- #endif
38
- #else
39
- #define CONFIG_ESP_FACE_DETECT_ENABLED 0
40
- #define CONFIG_ESP_FACE_RECOGNITION_ENABLED 0
41
- #endif
42
-
43
- #if CONFIG_ESP_FACE_DETECT_ENABLED
44
-
45
- #include < vector>
46
- #include " human_face_detect_msr01.hpp"
47
- #include " human_face_detect_mnp01.hpp"
48
-
49
- #define TWO_STAGE 1 /* <! 1: detect by two-stage which is more accurate but slower(with keypoints). */
50
- /* <! 0: detect by one-stage which is less accurate but faster(without keypoints). */
51
-
52
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
53
- #pragma GCC diagnostic ignored "-Wformat"
54
- #pragma GCC diagnostic ignored "-Wstrict-aliasing"
55
- #include " face_recognition_tool.hpp"
56
- #include " face_recognition_112_v1_s16.hpp"
57
- #include " face_recognition_112_v1_s8.hpp"
58
- #pragma GCC diagnostic error "-Wformat"
59
- #pragma GCC diagnostic warning "-Wstrict-aliasing"
60
-
61
- #define QUANT_TYPE 0 // if set to 1 => very large firmware, very slow, reboots when streaming...
62
-
63
- #define FACE_ID_SAVE_NUMBER 7
64
- #endif
65
-
66
- #define FACE_COLOR_WHITE 0x00FFFFFF
67
- #define FACE_COLOR_BLACK 0x00000000
68
- #define FACE_COLOR_RED 0x000000FF
69
- #define FACE_COLOR_GREEN 0x0000FF00
70
- #define FACE_COLOR_BLUE 0x00FF0000
71
- #define FACE_COLOR_YELLOW (FACE_COLOR_RED | FACE_COLOR_GREEN)
72
- #define FACE_COLOR_CYAN (FACE_COLOR_BLUE | FACE_COLOR_GREEN)
73
- #define FACE_COLOR_PURPLE (FACE_COLOR_BLUE | FACE_COLOR_RED)
74
- #endif
75
-
76
27
// Enable LED FLASH setting
77
28
#define CONFIG_LED_ILLUMINATOR_ENABLED 1
78
29
@@ -100,32 +51,6 @@ static const char *_STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %
100
51
httpd_handle_t stream_httpd = NULL ;
101
52
httpd_handle_t camera_httpd = NULL ;
102
53
103
- #if CONFIG_ESP_FACE_DETECT_ENABLED
104
-
105
- static int8_t detection_enabled = 0 ;
106
-
107
- // #if TWO_STAGE
108
- // static HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F);
109
- // static HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5);
110
- // #else
111
- // static HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F);
112
- // #endif
113
-
114
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
115
- static int8_t recognition_enabled = 0 ;
116
- static int8_t is_enrolling = 0 ;
117
-
118
- #if QUANT_TYPE
119
- // S16 model
120
- FaceRecognition112V1S16 recognizer;
121
- #else
122
- // S8 model
123
- FaceRecognition112V1S8 recognizer;
124
- #endif
125
- #endif
126
-
127
- #endif
128
-
129
54
typedef struct {
130
55
size_t size; // number of values used for filtering
131
56
size_t index; // current value index
@@ -166,105 +91,6 @@ static int ra_filter_run(ra_filter_t *filter, int value) {
166
91
}
167
92
#endif
168
93
169
- #if CONFIG_ESP_FACE_DETECT_ENABLED
170
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
171
- static void rgb_print (fb_data_t *fb, uint32_t color, const char *str) {
172
- fb_gfx_print (fb, (fb->width - (strlen (str) * 14 )) / 2 , 10 , color, str);
173
- }
174
-
175
- static int rgb_printf (fb_data_t *fb, uint32_t color, const char *format, ...) {
176
- char loc_buf[64 ];
177
- char *temp = loc_buf;
178
- int len;
179
- va_list arg;
180
- va_list copy;
181
- va_start (arg, format);
182
- va_copy (copy, arg);
183
- len = vsnprintf (loc_buf, sizeof (loc_buf), format, arg);
184
- va_end (copy);
185
- if (len >= sizeof (loc_buf)) {
186
- temp = (char *)malloc (len + 1 );
187
- if (temp == NULL ) {
188
- return 0 ;
189
- }
190
- }
191
- vsnprintf (temp, len + 1 , format, arg);
192
- va_end (arg);
193
- rgb_print (fb, color, temp);
194
- if (len > 64 ) {
195
- free (temp);
196
- }
197
- return len;
198
- }
199
- #endif
200
- static void draw_face_boxes (fb_data_t *fb, std::list<dl::detect::result_t > *results, int face_id) {
201
- int x, y, w, h;
202
- uint32_t color = FACE_COLOR_YELLOW;
203
- if (face_id < 0 ) {
204
- color = FACE_COLOR_RED;
205
- } else if (face_id > 0 ) {
206
- color = FACE_COLOR_GREEN;
207
- }
208
- if (fb->bytes_per_pixel == 2 ) {
209
- // color = ((color >> 8) & 0xF800) | ((color >> 3) & 0x07E0) | (color & 0x001F);
210
- color = ((color >> 16 ) & 0x001F ) | ((color >> 3 ) & 0x07E0 ) | ((color << 8 ) & 0xF800 );
211
- }
212
- int i = 0 ;
213
- for (std::list<dl::detect::result_t >::iterator prediction = results->begin (); prediction != results->end (); prediction++, i++) {
214
- // rectangle box
215
- x = (int )prediction->box [0 ];
216
- y = (int )prediction->box [1 ];
217
- w = (int )prediction->box [2 ] - x + 1 ;
218
- h = (int )prediction->box [3 ] - y + 1 ;
219
- if ((x + w) > fb->width ) {
220
- w = fb->width - x;
221
- }
222
- if ((y + h) > fb->height ) {
223
- h = fb->height - y;
224
- }
225
- fb_gfx_drawFastHLine (fb, x, y, w, color);
226
- fb_gfx_drawFastHLine (fb, x, y + h - 1 , w, color);
227
- fb_gfx_drawFastVLine (fb, x, y, h, color);
228
- fb_gfx_drawFastVLine (fb, x + w - 1 , y, h, color);
229
- #if TWO_STAGE
230
- // landmarks (left eye, mouth left, nose, right eye, mouth right)
231
- int x0, y0, j;
232
- for (j = 0 ; j < 10 ; j += 2 ) {
233
- x0 = (int )prediction->keypoint [j];
234
- y0 = (int )prediction->keypoint [j + 1 ];
235
- fb_gfx_fillRect (fb, x0, y0, 3 , 3 , color);
236
- }
237
- #endif
238
- }
239
- }
240
-
241
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
242
- static int run_face_recognition (fb_data_t *fb, std::list<dl::detect::result_t > *results) {
243
- std::vector<int > landmarks = results->front ().keypoint ;
244
- int id = -1 ;
245
-
246
- Tensor<uint8_t > tensor;
247
- tensor.set_element ((uint8_t *)fb->data ).set_shape ({fb->height , fb->width , 3 }).set_auto_free (false );
248
-
249
- int enrolled_count = recognizer.get_enrolled_id_num ();
250
-
251
- if (enrolled_count < FACE_ID_SAVE_NUMBER && is_enrolling) {
252
- id = recognizer.enroll_id (tensor, landmarks, " " , true );
253
- log_i (" Enrolled ID: %d" , id);
254
- rgb_printf (fb, FACE_COLOR_CYAN, " ID[%u]" , id);
255
- }
256
-
257
- face_info_t recognize = recognizer.recognize (tensor, landmarks);
258
- if (recognize.id >= 0 ) {
259
- rgb_printf (fb, FACE_COLOR_GREEN, " ID[%u]: %.2f" , recognize.id , recognize.similarity );
260
- } else {
261
- rgb_print (fb, FACE_COLOR_RED, " Intruder Alert!" );
262
- }
263
- return recognize.id ;
264
- }
265
- #endif
266
- #endif
267
-
268
94
#if CONFIG_LED_ILLUMINATOR_ENABLED
269
95
void enable_led (bool en) { // Turn LED On or Off
270
96
int duty = en ? led_duty : 0 ;
@@ -359,134 +185,28 @@ static esp_err_t capture_handler(httpd_req_t *req) {
359
185
snprintf (ts, 32 , " %lld.%06ld" , fb->timestamp .tv_sec , fb->timestamp .tv_usec );
360
186
httpd_resp_set_hdr (req, " X-Timestamp" , (const char *)ts);
361
187
362
- #if CONFIG_ESP_FACE_DETECT_ENABLED
363
- size_t out_len, out_width, out_height;
364
- uint8_t *out_buf;
365
- bool s;
366
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
367
- bool detected = false ;
368
- #endif
369
- int face_id = 0 ;
370
- if (!detection_enabled || fb->width > 400 ) {
371
- #endif
372
188
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
373
- size_t fb_len = 0 ;
189
+ size_t fb_len = 0 ;
374
190
#endif
375
- if (fb->format == PIXFORMAT_JPEG) {
191
+ if (fb->format == PIXFORMAT_JPEG) {
376
192
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
377
- fb_len = fb->len ;
193
+ fb_len = fb->len ;
378
194
#endif
379
- res = httpd_resp_send (req, (const char *)fb->buf , fb->len );
380
- } else {
381
- jpg_chunking_t jchunk = {req, 0 };
382
- res = frame2jpg_cb (fb, 80 , jpg_encode_stream, &jchunk) ? ESP_OK : ESP_FAIL;
383
- httpd_resp_send_chunk (req, NULL , 0 );
384
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
385
- fb_len = jchunk.len ;
386
- #endif
387
- }
388
- esp_camera_fb_return (fb);
389
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
390
- int64_t fr_end = esp_timer_get_time ();
391
- #endif
392
- log_i (" JPG: %uB %ums" , (uint32_t )(fb_len), (uint32_t )((fr_end - fr_start) / 1000 ));
393
- return res;
394
- #if CONFIG_ESP_FACE_DETECT_ENABLED
395
- }
396
-
397
- jpg_chunking_t jchunk = {req, 0 };
398
-
399
- if (fb->format == PIXFORMAT_RGB565
400
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
401
- && !recognition_enabled
402
- #endif
403
- ) {
404
- #if TWO_STAGE
405
- HumanFaceDetectMSR01 s1 (0 .1F , 0 .5F , 10 , 0 .2F );
406
- HumanFaceDetectMNP01 s2 (0 .5F , 0 .3F , 5 );
407
- std::list<dl::detect::result_t > &candidates = s1.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 });
408
- std::list<dl::detect::result_t > &results = s2.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 }, candidates);
409
- #else
410
- HumanFaceDetectMSR01 s1 (0 .3F , 0 .5F , 10 , 0 .2F );
411
- std::list<dl::detect::result_t > &results = s1.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 });
412
- #endif
413
- if (results.size () > 0 ) {
414
- fb_data_t rfb;
415
- rfb.width = fb->width ;
416
- rfb.height = fb->height ;
417
- rfb.data = fb->buf ;
418
- rfb.bytes_per_pixel = 2 ;
419
- rfb.format = FB_RGB565;
420
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
421
- detected = true ;
422
- #endif
423
- draw_face_boxes (&rfb, &results, face_id);
424
- }
425
- s = fmt2jpg_cb (fb->buf , fb->len , fb->width , fb->height , PIXFORMAT_RGB565, 90 , jpg_encode_stream, &jchunk);
426
- esp_camera_fb_return (fb);
195
+ res = httpd_resp_send (req, (const char *)fb->buf , fb->len );
427
196
} else {
428
- out_len = fb->width * fb->height * 3 ;
429
- out_width = fb->width ;
430
- out_height = fb->height ;
431
- out_buf = (uint8_t *)malloc (out_len);
432
- if (!out_buf) {
433
- log_e (" out_buf malloc failed" );
434
- httpd_resp_send_500 (req);
435
- return ESP_FAIL;
436
- }
437
- s = fmt2rgb888 (fb->buf , fb->len , fb->format , out_buf);
438
- esp_camera_fb_return (fb);
439
- if (!s) {
440
- free (out_buf);
441
- log_e (" To rgb888 failed" );
442
- httpd_resp_send_500 (req);
443
- return ESP_FAIL;
444
- }
445
-
446
- fb_data_t rfb;
447
- rfb.width = out_width;
448
- rfb.height = out_height;
449
- rfb.data = out_buf;
450
- rfb.bytes_per_pixel = 3 ;
451
- rfb.format = FB_BGR888;
452
-
453
- #if TWO_STAGE
454
- HumanFaceDetectMSR01 s1 (0 .1F , 0 .5F , 10 , 0 .2F );
455
- HumanFaceDetectMNP01 s2 (0 .5F , 0 .3F , 5 );
456
- std::list<dl::detect::result_t > &candidates = s1.infer ((uint8_t *)out_buf, {(int )out_height, (int )out_width, 3 });
457
- std::list<dl::detect::result_t > &results = s2.infer ((uint8_t *)out_buf, {(int )out_height, (int )out_width, 3 }, candidates);
458
- #else
459
- HumanFaceDetectMSR01 s1 (0 .3F , 0 .5F , 10 , 0 .2F );
460
- std::list<dl::detect::result_t > &results = s1.infer ((uint8_t *)out_buf, {(int )out_height, (int )out_width, 3 });
461
- #endif
462
-
463
- if (results.size () > 0 ) {
197
+ jpg_chunking_t jchunk = {req, 0 };
198
+ res = frame2jpg_cb (fb, 80 , jpg_encode_stream, &jchunk) ? ESP_OK : ESP_FAIL;
199
+ httpd_resp_send_chunk (req, NULL , 0 );
464
200
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
465
- detected = true ;
201
+ fb_len = jchunk. len ;
466
202
#endif
467
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
468
- if (recognition_enabled) {
469
- face_id = run_face_recognition (&rfb, &results);
470
- }
471
- #endif
472
- draw_face_boxes (&rfb, &results, face_id);
473
- }
474
-
475
- s = fmt2jpg_cb (out_buf, out_len, out_width, out_height, PIXFORMAT_RGB888, 90 , jpg_encode_stream, &jchunk);
476
- free (out_buf);
477
- }
478
-
479
- if (!s) {
480
- log_e (" JPEG compression failed" );
481
- httpd_resp_send_500 (req);
482
- return ESP_FAIL;
483
203
}
204
+ esp_camera_fb_return (fb);
484
205
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
485
206
int64_t fr_end = esp_timer_get_time ();
486
207
#endif
487
- log_i (" FACE : %uB %ums %s%d " , (uint32_t )(jchunk. len ), (uint32_t )((fr_end - fr_start) / 1000 ), detected ? " DETECTED " : " " , face_id );
208
+ log_i (" JPG : %uB %ums" , (uint32_t )(fb_len ), (uint32_t )((fr_end - fr_start) / 1000 ));
488
209
return res;
489
- #endif
490
210
}
491
211
492
212
static esp_err_t stream_handler (httpd_req_t *req) {
@@ -496,26 +216,6 @@ static esp_err_t stream_handler(httpd_req_t *req) {
496
216
size_t _jpg_buf_len = 0 ;
497
217
uint8_t *_jpg_buf = NULL ;
498
218
char *part_buf[128 ];
499
- #if CONFIG_ESP_FACE_DETECT_ENABLED
500
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
501
- bool detected = false ;
502
- int64_t fr_ready = 0 ;
503
- int64_t fr_recognize = 0 ;
504
- int64_t fr_encode = 0 ;
505
- int64_t fr_face = 0 ;
506
- int64_t fr_start = 0 ;
507
- #endif
508
- int face_id = 0 ;
509
- size_t out_len = 0 , out_width = 0 , out_height = 0 ;
510
- uint8_t *out_buf = NULL ;
511
- bool s = false ;
512
- #if TWO_STAGE
513
- HumanFaceDetectMSR01 s1 (0 .1F , 0 .5F , 10 , 0 .2F );
514
- HumanFaceDetectMNP01 s2 (0 .5F , 0 .3F , 5 );
515
- #else
516
- HumanFaceDetectMSR01 s1 (0 .3F , 0 .5F , 10 , 0 .2F );
517
- #endif
518
- #endif
519
219
520
220
static int64_t last_frame = 0 ;
521
221
if (!last_frame) {
@@ -536,152 +236,25 @@ static esp_err_t stream_handler(httpd_req_t *req) {
536
236
#endif
537
237
538
238
while (true ) {
539
- #if CONFIG_ESP_FACE_DETECT_ENABLED
540
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
541
- detected = false ;
542
- #endif
543
- face_id = 0 ;
544
- #endif
545
-
546
239
fb = esp_camera_fb_get ();
547
240
if (!fb) {
548
241
log_e (" Camera capture failed" );
549
242
res = ESP_FAIL;
550
243
} else {
551
244
_timestamp.tv_sec = fb->timestamp .tv_sec ;
552
245
_timestamp.tv_usec = fb->timestamp .tv_usec ;
553
- #if CONFIG_ESP_FACE_DETECT_ENABLED
554
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
555
- fr_start = esp_timer_get_time ();
556
- fr_ready = fr_start;
557
- fr_encode = fr_start;
558
- fr_recognize = fr_start;
559
- fr_face = fr_start;
560
- #endif
561
- if (!detection_enabled || fb->width > 400 ) {
562
- #endif
563
- if (fb->format != PIXFORMAT_JPEG) {
564
- bool jpeg_converted = frame2jpg (fb, 80 , &_jpg_buf, &_jpg_buf_len);
565
- esp_camera_fb_return (fb);
566
- fb = NULL ;
567
- if (!jpeg_converted) {
568
- log_e (" JPEG compression failed" );
569
- res = ESP_FAIL;
570
- }
571
- } else {
572
- _jpg_buf_len = fb->len ;
573
- _jpg_buf = fb->buf ;
246
+ if (fb->format != PIXFORMAT_JPEG) {
247
+ bool jpeg_converted = frame2jpg (fb, 80 , &_jpg_buf, &_jpg_buf_len);
248
+ esp_camera_fb_return (fb);
249
+ fb = NULL ;
250
+ if (!jpeg_converted) {
251
+ log_e (" JPEG compression failed" );
252
+ res = ESP_FAIL;
574
253
}
575
- #if CONFIG_ESP_FACE_DETECT_ENABLED
576
254
} else {
577
- if (fb->format == PIXFORMAT_RGB565
578
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
579
- && !recognition_enabled
580
- #endif
581
- ) {
582
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
583
- fr_ready = esp_timer_get_time ();
584
- #endif
585
- #if TWO_STAGE
586
- std::list<dl::detect::result_t > &candidates = s1.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 });
587
- std::list<dl::detect::result_t > &results = s2.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 }, candidates);
588
- #else
589
- std::list<dl::detect::result_t > &results = s1.infer ((uint16_t *)fb->buf , {(int )fb->height , (int )fb->width , 3 });
590
- #endif
591
- #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
592
- fr_face = esp_timer_get_time ();
593
- fr_recognize = fr_face;
594
- #endif
595
- if (results.size () > 0 ) {
596
- fb_data_t rfb;
597
- rfb.width = fb->width ;
598
- rfb.height = fb->height ;
599
- rfb.data = fb->buf ;
600
- rfb.bytes_per_pixel = 2 ;
601
- rfb.format = FB_RGB565;
602
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
603
- detected = true ;
604
- #endif
605
- draw_face_boxes (&rfb, &results, face_id);
606
- }
607
- s = fmt2jpg (fb->buf , fb->len , fb->width , fb->height , PIXFORMAT_RGB565, 80 , &_jpg_buf, &_jpg_buf_len);
608
- esp_camera_fb_return (fb);
609
- fb = NULL ;
610
- if (!s) {
611
- log_e (" fmt2jpg failed" );
612
- res = ESP_FAIL;
613
- }
614
- #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
615
- fr_encode = esp_timer_get_time ();
616
- #endif
617
- } else {
618
- out_len = fb->width * fb->height * 3 ;
619
- out_width = fb->width ;
620
- out_height = fb->height ;
621
- out_buf = (uint8_t *)malloc (out_len);
622
- if (!out_buf) {
623
- log_e (" out_buf malloc failed" );
624
- res = ESP_FAIL;
625
- } else {
626
- s = fmt2rgb888 (fb->buf , fb->len , fb->format , out_buf);
627
- esp_camera_fb_return (fb);
628
- fb = NULL ;
629
- if (!s) {
630
- free (out_buf);
631
- log_e (" To rgb888 failed" );
632
- res = ESP_FAIL;
633
- } else {
634
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
635
- fr_ready = esp_timer_get_time ();
636
- #endif
637
-
638
- fb_data_t rfb;
639
- rfb.width = out_width;
640
- rfb.height = out_height;
641
- rfb.data = out_buf;
642
- rfb.bytes_per_pixel = 3 ;
643
- rfb.format = FB_BGR888;
644
-
645
- #if TWO_STAGE
646
- std::list<dl::detect::result_t > &candidates = s1.infer ((uint8_t *)out_buf, {(int )out_height, (int )out_width, 3 });
647
- std::list<dl::detect::result_t > &results = s2.infer ((uint8_t *)out_buf, {(int )out_height, (int )out_width, 3 }, candidates);
648
- #else
649
- std::list<dl::detect::result_t > &results = s1.infer ((uint8_t *)out_buf, {(int )out_height, (int )out_width, 3 });
650
- #endif
651
-
652
- #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
653
- fr_face = esp_timer_get_time ();
654
- fr_recognize = fr_face;
655
- #endif
656
-
657
- if (results.size () > 0 ) {
658
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
659
- detected = true ;
660
- #endif
661
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
662
- if (recognition_enabled) {
663
- face_id = run_face_recognition (&rfb, &results);
664
- #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
665
- fr_recognize = esp_timer_get_time ();
666
- #endif
667
- }
668
- #endif
669
- draw_face_boxes (&rfb, &results, face_id);
670
- }
671
- s = fmt2jpg (out_buf, out_len, out_width, out_height, PIXFORMAT_RGB888, 90 , &_jpg_buf, &_jpg_buf_len);
672
- free (out_buf);
673
- if (!s) {
674
- log_e (" fmt2jpg failed" );
675
- res = ESP_FAIL;
676
- }
677
- #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
678
- fr_encode = esp_timer_get_time ();
679
- #endif
680
- }
681
- }
682
- }
255
+ _jpg_buf_len = fb->len ;
256
+ _jpg_buf = fb->buf ;
683
257
}
684
- #endif
685
258
}
686
259
if (res == ESP_OK) {
687
260
res = httpd_resp_send_chunk (req, _STREAM_BOUNDARY, strlen (_STREAM_BOUNDARY));
@@ -707,30 +280,14 @@ static esp_err_t stream_handler(httpd_req_t *req) {
707
280
}
708
281
int64_t fr_end = esp_timer_get_time ();
709
282
710
- #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
711
- int64_t ready_time = (fr_ready - fr_start) / 1000 ;
712
- int64_t face_time = (fr_face - fr_ready) / 1000 ;
713
- int64_t recognize_time = (fr_recognize - fr_face) / 1000 ;
714
- int64_t encode_time = (fr_encode - fr_recognize) / 1000 ;
715
- int64_t process_time = (fr_encode - fr_start) / 1000 ;
716
- #endif
717
-
718
283
int64_t frame_time = fr_end - last_frame;
719
284
frame_time /= 1000 ;
720
285
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
721
286
uint32_t avg_frame_time = ra_filter_run (&ra_filter, frame_time);
722
287
#endif
723
288
log_i (
724
- " MJPG: %uB %ums (%.1ffps), AVG: %ums (%.1ffps)"
725
- #if CONFIG_ESP_FACE_DETECT_ENABLED
726
- " , %u+%u+%u+%u=%u %s%d"
727
- #endif
728
- ,
729
- (uint32_t )(_jpg_buf_len), (uint32_t )frame_time, 1000.0 / (uint32_t )frame_time, avg_frame_time, 1000.0 / avg_frame_time
730
- #if CONFIG_ESP_FACE_DETECT_ENABLED
731
- ,
732
- (uint32_t )ready_time, (uint32_t )face_time, (uint32_t )recognize_time, (uint32_t )encode_time, (uint32_t )process_time, (detected) ? " DETECTED " : " " , face_id
733
- #endif
289
+ " MJPG: %uB %ums (%.1ffps), AVG: %ums (%.1ffps)" , (uint32_t )(_jpg_buf_len), (uint32_t )frame_time, 1000.0 / (uint32_t )frame_time, avg_frame_time,
290
+ 1000.0 / avg_frame_time
734
291
);
735
292
}
736
293
@@ -841,28 +398,6 @@ static esp_err_t cmd_handler(httpd_req_t *req) {
841
398
enable_led (true );
842
399
}
843
400
}
844
- #endif
845
-
846
- #if CONFIG_ESP_FACE_DETECT_ENABLED
847
- else if (!strcmp (variable, " face_detect" )) {
848
- detection_enabled = val;
849
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
850
- if (!detection_enabled) {
851
- recognition_enabled = 0 ;
852
- }
853
- #endif
854
- }
855
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
856
- else if (!strcmp (variable, " face_enroll" )) {
857
- is_enrolling = !is_enrolling;
858
- log_i (" Enrolling: %s" , is_enrolling ? " true" : " false" );
859
- } else if (!strcmp (variable, " face_recognize" )) {
860
- recognition_enabled = val;
861
- if (recognition_enabled) {
862
- detection_enabled = val;
863
- }
864
- }
865
- #endif
866
401
#endif
867
402
else {
868
403
log_i (" Unknown command: %s" , variable);
@@ -947,13 +482,6 @@ static esp_err_t status_handler(httpd_req_t *req) {
947
482
p += sprintf (p, " ,\" led_intensity\" :%u" , led_duty);
948
483
#else
949
484
p += sprintf (p, " ,\" led_intensity\" :%d" , -1 );
950
- #endif
951
- #if CONFIG_ESP_FACE_DETECT_ENABLED
952
- p += sprintf (p, " ,\" face_detect\" :%u" , detection_enabled);
953
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
954
- p += sprintf (p, " ,\" face_enroll\" :%u," , is_enrolling);
955
- p += sprintf (p, " \" face_recognize\" :%u" , recognition_enabled);
956
- #endif
957
485
#endif
958
486
*p++ = ' }' ;
959
487
*p++ = 0 ;
@@ -1289,12 +817,6 @@ void startCameraServer() {
1289
817
1290
818
ra_filter_init (&ra_filter, 20 );
1291
819
1292
- #if CONFIG_ESP_FACE_RECOGNITION_ENABLED
1293
- recognizer.set_partition (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, " fr" );
1294
-
1295
- // load ids from flash partition
1296
- recognizer.set_ids_from_flash ();
1297
- #endif
1298
820
log_i (" Starting web server on port: '%d'" , config.server_port );
1299
821
if (httpd_start (&camera_httpd, &config) == ESP_OK) {
1300
822
httpd_register_uri_handler (camera_httpd, &index_uri);
0 commit comments