8000 Update camera example to support face detection and recognition (#6603) · rtu-dataframe/arduino-esp32@12045d3 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 header class="HeaderMktg header-logged-out js-details-container js-header Details f4 py-3" role="banner" data-is-top="true" data-color-mode=light data-light-theme=light data-dark-theme=dark>

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 12045d3

Browse files
authored
Update camera example to support face detection and recognition (espressif#6603)
Fixes: espressif#6508
1 parent 45b7fa0 commit 12045d3

File tree

7 files changed

+408
-210
lines changed

7 files changed

+408
-210
lines changed

libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,35 @@
66
// Ensure ESP32 Wrover Module or other board with PSRAM is selected
77
// Partial images will be transmitted if image exceeds buffer size
88
//
9+
// You must select partition scheme from the board menu that has at least 3MB APP space.
10+
// Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
11+
// seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well
912

13+
// ===================
1014
// Select camera model
11-
#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
15+
// ===================
16+
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
1217
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
18+
//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
1319
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
1420
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
1521
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
1622
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
1723
//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
18-
//#define CAMERA_MODEL_AI_THINKER // Has PSRAM
24+
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
1925
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
26+
// ** Espressif Internal Boards **
27+
//#define CAMERA_MODEL_ESP32_CAM_BOARD
28+
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
29+
//#define CAMERA_MODEL_ESP32S3_CAM_LCD
2030

2131
#include "camera_pins.h"
2232

23-
const char* ssid = "*********";
24-
const char* password = "*********";
8000
33+
// ===========================
34+
// Enter your WiFi credentials
35+
// ===========================
36+
const char* ssid = "**********";
37+
const char* password = "**********";
2538

2639
void startCameraServer();
2740

@@ -50,19 +63,32 @@ void setup() {
5063
config.pin_pwdn = PWDN_GPIO_NUM;
5164
config.pin_reset = RESET_GPIO_NUM;
5265
config.xclk_freq_hz = 20000000;
53-
config.pixel_format = PIXFORMAT_JPEG;
66+
config.frame_size = FRAMESIZE_UXGA;
67+
config.pixel_format = PIXFORMAT_JPEG; // for streaming
68+
//config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
69+
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
70+
config.fb_location = CAMERA_FB_IN_PSRAM;
71+
config.jpeg_quality = 12;
72+
config.fb_count = 1;
5473

5574
// if PSRAM IC present, init with UXGA resolution and higher JPEG quality
5675
// for larger pre-allocated frame buffer.
57-
if(psramFound()){
58-
config.frame_size = FRAMESIZE_UXGA;
59-
config.jpeg_quality = 10;
60-
config.fb_count = 2;
76+
if(config.pixel_format == PIXFORMAT_JPEG){
77+
if(psramFound()){
78+
config.jpeg_quality = 10;
79+
config.fb_count = 2;
80+
config.grab_mode = CAMERA_GRAB_LATEST;
81+
} else {
82+
// Limit the frame size when PSRAM is not available
83+
config.frame_size = FRAMESIZE_SVGA;
84+
config.fb_location = CAMERA_FB_IN_DRAM;
85+
}
6186
} else {
62-
config.frame_size = FRAMESIZE_SVGA;
63-
config.jpeg_quality = 12;
64-
config.fb_count = 1;
65-
config.fb_location = CAMERA_FB_IN_DRAM;
87+
// Best option for face detection/recognition
88+
config.frame_size = FRAMESIZE_240X240;
89+
#if CONFIG_IDF_TARGET_ESP32S3
90+
config.fb_count = 2;
91+
#endif
6692
}
6793

6894
#if defined(CAMERA_MODEL_ESP_EYE)
@@ -85,14 +111,21 @@ void setup() {
85111
s->set_saturation(s, -2); // lower the saturation
86112
}
87113
// drop down frame size for higher initial frame rate
88-
s->set_framesize(s, FRAMESIZE_QVGA);
114+
if(config.pixel_format == PIXFORMAT_JPEG){
115+
s->set_framesize(s, FRAMESIZE_QVGA);
116+
}
89117

90118
#if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
91119
s->set_vflip(s, 1);
92120
s->set_hmirror(s, 1);
93121
#endif
94122

123+
#if defined(CAMERA_MODEL_ESP32S3_EYE)
124+
s->set_vflip(s, 1);
125+
#endif
126+
95127
WiFi.begin(ssid, password);
128+
WiFi.setSleep(false);
96129

97130
while (WiFi.status() != WL_CONNECTED) {
98131
delay(500);
@@ -109,6 +142,6 @@ void setup() {
109142
}
110143

111144
void loop() {
112-
// put your main code here, to run repeatedly:
145+
// Do nothing. Everything is done in another task by the web server
113146
delay(10000);
114147
}

0 commit comments

Comments
 (0)
0