File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
src/eloquent_esp32cam/face Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ namespace Eloquent {
4545 #if defined(ELOQUENT_EXTRA_PUBSUB_H)
4646 PubSub<FaceDetection> mqtt;
4747 #endif
48- uint8_t image[ 240 * 240 * 3 ] ;
48+ uint8_t *image ;
4949 face_t first;
5050 face_t faces[MAX_FACES];
5151
@@ -55,13 +55,20 @@ namespace Eloquent {
5555 FaceDetection () :
5656 exception (" FaceDetection" ),
5757 daemon (this ),
58+ image (NULL ),
5859 #if defined(ELOQUENT_EXTRA_PUBSUB_H)
5960 mqtt (this ),
6061 #endif
6162 _twoStages (false ),
6263 _confidence(0.5 )
6364 {
64- memset (image, 0 , sizeof (image));
65+ }
66+
67+ /* *
68+ * Destructor
69+ */
70+ ~FaceDetection () {
71+ free (image);
6572 }
6673
6774 /* *
@@ -91,6 +98,8 @@ namespace Eloquent {
9198 * Perform detection
9299 */
93100 Exception& run () {
101+ allocateImageBuffer ();
102+
94103 // assert 240x240
95104 if (camera.resolution .getWidth () != 240 || camera.resolution .getHeight () != 240 )
96105 return exception.set (" Face detection only works at 240x240" );
@@ -290,6 +299,25 @@ namespace Eloquent {
290299 }
291300 }
292301 }
302+
303+ /* *
304+ *
305+ */
306+ void allocateImageBuffer () {
307+ if (image != NULL )
308+ return ;
309+
310+ const uint32_t memsize = 240L * 240L * 3 ;
311+
312+ if (psramFound ()) {
313+ ESP_LOGD (" FaceDetection" , " Allocating %d bytes into PSRAM" , memsize);
314+ image = (uint8_t *) ps_malloc (memsize);
315+ }
316+ else {
317+ ESP_LOGD (" FaceDetection" , " Allocating %d bytes into RAM" , memsize);
318+ image = (uint8_t *) malloc (memsize);
319+ }
320+ }
293321 };
294322 }
295323 }
You can’t perform that action at this time.
0 commit comments