|
1 |
| -# Unleash the full power of you ESP32 camera |
2 |
| - |
3 |
| -This Arduino library kickstarts your ESP32 camera projects |
4 |
| -by providing you a set of tools to easily interact your the camera. |
5 |
| - |
6 |
| -## Take a picture |
7 |
| - |
8 |
| -Forget complex configurations and verbose code. |
9 |
| - |
10 |
| -```cpp |
11 |
| -#include <eloquent_esp32cam.h> |
12 |
| - |
13 |
| -using eloq::camera; |
14 |
| - |
15 |
| -void setup() { |
16 |
| - delay(3000); |
17 |
| - Serial.begin(115200); |
18 |
| - Serial.println("___GET YOUR FIRST PICTURE___"); |
19 |
| - |
20 |
| - camera.pinout.aithinker(); |
21 |
| - camera.brownout.disable(); |
22 |
| - camera.resolution.vga(); |
23 |
| - |
24 |
| - while (!camera.begin().isOk()) |
25 |
| - Serial.println(camera.exception.toString()); |
26 |
| -} |
27 |
| - |
28 |
| -void loop() { |
29 |
| - if (!camera.capture().isOk()) { |
30 |
| - Serial.println(camera.exception.toString()); |
31 |
| - return; |
32 |
| - } |
33 |
| - |
34 |
| - Serial.printf( |
35 |
| - "JPEG size in bytes: %d. Width: %dpx. Height: %dpx.\n", |
36 |
| - camera.getSizeInBytes(), |
37 |
| - camera.resolution.getWidth(), |
38 |
| - camera.resolution.getHeight() |
39 |
| - ); |
40 |
| -} |
41 |
| -``` |
42 |
| - |
43 |
| -## Save picture to SD card |
44 |
| - |
45 |
| -Timestamped file storage on your SD card that you can finally understand! |
46 |
| - |
47 |
| -```cpp |
48 |
| -#include <eloquent_esp32cam.h> |
49 |
| -#include <eloquent_esp32cam/extra/esp32/ntp.h> |
50 |
| -#include <eloquent_esp32cam/extra/esp32/fs/sdmmc.h> |
51 |
| - |
52 |
| -void setup() { |
53 |
| - delay(3000); |
54 |
| - Serial.begin(115200); |
55 |
| - Serial.println("___SAVE PIC TO SD CARD___"); |
56 |
| - |
57 |
| - camera.pinout.freenove_s3(); |
58 |
| - camera.brownout.disable(); |
59 |
| - camera.resolution.vga(); |
60 |
| - camera.quality.high(); |
61 |
| - |
62 |
| - ntp.offsetFromGreenwhich(0); |
63 |
| - ntp.isDaylight(); |
64 |
| - ntp.server("pool.ntp.org"); |
65 |
| - |
66 |
| - // init camera |
67 |
| - while (!camera.begin().isOk()) |
68 |
| - Serial.println(camera.exception.toString()); |
69 |
| - |
70 |
| - // init SD |
71 |
| - while (!sdmmc.begin().isOk()) |
72 |
| - Serial.println(sdmmc.exception.toString()); |
73 |
| - |
74 |
| - // connect to WiFi to sync NTP |
75 |
| - while (!wifi.connect().isOk()) |
76 |
| - Serial.println(wifi.exception.toString()); |
77 |
| - |
78 |
| - // get NTP time |
79 |
| - while (!ntp.begin().isOk()) |
80 |
| - Serial.println(ntp.exception.toString()); |
81 |
| - |
82 |
| - Serial.println("Camera OK"); |
83 |
| - Serial.println("SD card OK"); |
84 |
| - Serial.println("NTP OK"); |
85 |
| - Serial.print("Current time is "); |
86 |
| - Serial.println(ntp.datetime()); |
87 |
| -} |
88 |
| - |
89 |
| -void loop() { |
90 |
| - if (!camera.capture().isOk()) { |
91 |
| - Serial.println(camera.exception.toString()); |
92 |
| - return; |
93 |
| - } |
94 |
| - |
95 |
| - // save under nested directory |
96 |
| - String date = ntp.date(); |
97 |
| - String datetime = ntp.datetime(); |
98 |
| - |
99 |
| - if (sdmmc.save(camera.frame).inside(date).to(datetime, "jpg").isOk()) { |
100 |
| - Serial.print("File written to "); |
101 |
| - Serial.println(sdmmc.session.lastFilename); |
102 |
| - } |
103 |
| - else Serial.println(sdmmc.session.exception.toString()); |
104 |
| -} |
105 |
| -``` |
106 |
| - |
107 |
| -## Object detection |
108 |
| - |
109 |
| -Running Edge Impulse FOMO object detection is a piece of cake. |
110 |
| - |
111 |
| -```cpp |
112 |
| -#include <your-fomo-project_inferencing.h> |
113 |
| -#include <eloquent_esp32cam.h> |
114 |
| -#include <eloquent_esp32cam/edgeimpulse/fomo.h> |
115 |
| - |
116 |
| -using eloq::camera; |
117 |
| -using eloq::ei::fomo; |
118 |
| - |
119 |
| -void setup() { |
120 |
| - delay(3000); |
121 |
| - Serial.begin(115200); |
122 |
| - Serial.println("__EDGE IMPULSE FOMO (NO-PSRAM)__"); |
123 |
| - |
124 |
| - // camera settings |
125 |
| - camera.pinout.freenove_s3(); |
126 |
| - camera.brownout.disable(); |
127 |
| - camera.resolution.yolo(); |
128 |
| - camera.pixformat.rgb565(); |
129 |
| - |
130 |
| - // init camera |
131 |
| - while (!camera.begin().isOk()) |
132 |
| - Serial.println(camera.exception.toString()); |
133 |
| - |
134 |
| - Serial.println("Camera OK"); |
135 |
| - Serial.println("Put object in front of camera"); |
136 |
| -} |
137 |
| - |
138 |
| - |
139 |
| -void loop() { |
140 |
| - if (!camera.capture().isOk()) { |
141 |
| - Serial.println(camera.exception.toString()); |
142 |
| - return; |
143 |
| - } |
144 |
| - |
145 |
| - // run FOMO |
146 |
| - if (!fomo.run().isOk()) { |
147 |
| - Serial.println(fomo.exception.toString()); |
148 |
| - return; |
149 |
| - } |
150 |
| - |
151 |
| - // how many objects were found? |
152 |
| - Serial.printf( |
153 |
| - "Found %d object(s) in %dms\n", |
154 |
| - fomo.count(), |
155 |
| - fomo.benchmark.millis() |
156 |
| - ); |
157 |
| - |
158 |
| - // if no object is detected, return |
159 |
| - if (!fomo.foundAnyObject()) |
160 |
| - return; |
161 |
| - |
162 |
| - // if you expect to find a single object, use fomo.first |
163 |
| - Serial.printf( |
164 |
| - "Found %s at (x = %d, y = %d) (size %d x %d). " |
165 |
| - "Proba is %.2f\n", |
166 |
| - fomo.first.label, |
167 |
| - fomo.first.x, |
168 |
| - fomo.first.y, |
169 |
| - fomo.first.width, |
170 |
| - fomo.first.height, |
171 |
| - fomo.first.proba |
172 |
| - ); |
173 |
| - |
174 |
| - // if you expect to find many objects, use fomo.forEach |
175 |
| - if (fomo.count() > 1) { |
176 |
| - fomo.forEach([](int i, bbox_t bbox) { |
177 |
| - Serial.printf( |
178 |
| - "#%d) Found %s at (x = %d, y = %d) (size %d x %d). " |
179 |
| - "Proba is %.2f\n", |
180 |
| - i + 1, |
181 |
| - bbox.label, |
182 |
| - bbox.x, |
183 |
| - bbox.y, |
184 |
| - bbox.width, |
185 |
| - bbox.height, |
186 |
| - bbox.proba |
187 |
| - ); |
188 |
| - }); |
189 |
| - } |
190 |
| -} |
191 |
| -``` |
| 1 | +RoboSoccer Camera Object Detection |
0 commit comments