Skip to content

Commit 94988ec

Browse files
set camera frame manually + switch fomo memory allocation to PSRAM
1 parent dc520c5 commit 94988ec

File tree

6 files changed

+56
-23
lines changed

6 files changed

+56
-23
lines changed

src/eloquent_esp32cam/camera/camera.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ namespace Eloquent {
9595
return exception.clear();
9696
}
9797

98+
/**
99+
* Manually set frame
100+
*
101+
* @param newFrame
102+
*/
103+
void setFrame(camera_fb_t *newFrame) {
104+
frame = newFrame;
105+
}
106+
98107
/**
99108
* Capture new frame
100109
*/

src/eloquent_esp32cam/camera/resolution.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ namespace Eloquent {
278278
case FRAMESIZE_QCIF: qcif(); break;
279279
case FRAMESIZE_HQVGA: hqvga(); break;
280280
case FRAMESIZE_240X240: _240x240(); break;
281-
case FRAMESIZE_QVGA: square240(); break;
281+
case FRAMESIZE_QVGA: qvga(); break;
282282
case FRAMESIZE_CIF: cif(); break;
283283
case FRAMESIZE_HVGA: hvga(); break;
284284
case FRAMESIZE_VGA: vga(); break;

src/eloquent_esp32cam/edgeimpulse/image.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ namespace Eloquent {
4747
#endif
4848
_buf(NULL),
4949
_len(0) {
50+
51+
signal.get_data = [this](size_t offset, size_t length, float *out) {
52+
return getData(offset, length, out);
53+
};
5054
}
5155

5256
/**
@@ -144,8 +148,8 @@ namespace Eloquent {
144148
srcWidth = newWidth;
145149
srcHeight = newHeight;
146150

147-
if (_buf == NULL) _buf = (uint8_t*) malloc(newSize * 2);
148-
else _buf = (uint8_t*) realloc(_buf, newSize * 2);
151+
if (_buf == NULL) _buf = (uint8_t*) ps_malloc(newSize * 2);
152+
else _buf = (uint8_t*) ps_realloc(_buf, newSize * 2);
149153
}
150154

151155
if (_buf == NULL)
@@ -169,10 +173,6 @@ namespace Eloquent {
169173
_dx = ((float) srcWidth) / EI_CLASSIFIER_INPUT_WIDTH;
170174
_dy = ((float) srcHeight) / EI_CLASSIFIER_INPUT_HEIGHT;
171175

172-
signal.get_data = [this](size_t offset, size_t length, float *out) {
173-
return getData(offset, length, out);
174-
};
175-
176176
return true;
177177
}
178178

src/eloquent_esp32cam/extra/esp32/multiprocessing/mutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace Eloquent {
4747

4848
if (mutex == NULL) {
4949
ESP_LOGE("Mutex", "Cannot create mutex %s", name);
50-
return false;
50+
return (_ok = false);
5151
}
5252

5353
if (xSemaphoreTake(mutex, ticks) != pdTRUE) {

src/eloquent_esp32cam/transform/crop.h

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ namespace Eloquent {
5656
return from((uint16_t*) frame.data, frame.width, frame.height);
5757
}
5858

59+
/**
60+
* Set src image
61+
* @param frame
62+
* @return
63+
*/
64+
Crop& from(camera_fb_t *frame) {
65+
return from((uint16_t*) frame->buf, frame->width, frame->height);
66+
}
67+
5968
/**
6069
*
6170
*/
@@ -96,12 +105,8 @@ namespace Eloquent {
96105
_src.x2 = _src.width;
97106
_src.y1 = 0;
98107
_src.y2 = _src.height;
99-
_out.x1 = 0;
100-
_out.x2 = _out.width;
101-
_out.y1 = 0;
102-
_out.y2 = _out.height;
103108

104-
return *this;
109+
return offset(0, 0);
105110
}
106111

107112
/**
@@ -116,10 +121,8 @@ namespace Eloquent {
116121
_src.y1 = dy;
117122
_src.x2 = _src.width - dx;
118123
_src.y2 = _src.height - dy;
119-
_out.x1 = 0;
120-
_out.y1 = 0;
121-
_out.x2 = _out.width;
122-
_out.y2 = _out.height;
124+
125+
return offset(0, 0);
123126
}
124127
else if (_out.width > _src.width) {
125128
uint16_t dx = (_out.width - _src.width) / 2;
@@ -138,6 +141,24 @@ namespace Eloquent {
138141
return *this;
139142
}
140143

144+
/**
145+
* Manually set crop area origin
146+
* @param x
147+
* @param y
148+
* @return
149+
*/
150+
Crop& offset(int16_t x, int16_t y) {
151+
if (x < 0) x += _src.width;
152+
if (y < 0) y += _src.height;
153+
154+
_src.x1 = x;
155+
_src.x2 = x + _out.width;
156+
_src.y1 = y;
157+
_src.y2 = y + _out.height;
158+
159+
return *this;
160+
}
161+
141162
/**
142163
* No interpolation
143164
*/
@@ -150,7 +171,7 @@ namespace Eloquent {
150171
/**
151172
* Use mean interpolation
152173
*/
153-
Crop& mean() {
174+
Crop& linear() {
154175
_algo = IMAGE_RESIZE_MEAN;
155176

156177
return *this;
@@ -184,9 +205,9 @@ namespace Eloquent {
184205
if (_out.channels != 1 && _out.channels != 3)
185206
return exception.set("Output channels must be 1 (gray) or 3 (rgb)");
186207

187-
ESP_LOGI("Crop", "_src: w=%d, h=%d, y1=%d, y2=%d, x1=%d, x2=%d", _src.width, _src.height, _src.y1, _src.y2, _src.x1, _src.x2);
188-
ESP_LOGI("Crop", "_out: w=%d, h=%d, y1=%d, y2=%d, x1=%d, x2=%d", _out.width, _out.height, _out.y1, _out.y2, _out.x1, _out.x2);
189-
208+
ESP_LOGD("Crop", "src: w=%d, h=%d, y1=%d, y2=%d, x1=%d, x2=%d", _src.width, _src.height, _src.y1, _src.y2, _src.x1, _src.x2);
209+
ESP_LOGD("Crop", "out: w=%d, h=%d, y1=%d, y2=%d, x1=%d, x2=%d", _out.width, _out.height, _out.y1, _out.y2, _out.x1, _out.x2);
210+
190211
crop_and_resize(
191212
out,
192213
_out.height,

src/eloquent_esp32cam/viz/ei/fomo_stream.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,15 @@ namespace Eloquent {
9999
fomo.forEach([client](int i, eloq::ei::bbox_t bbox) {
100100
ESP_LOGI(
101101
"FOMO",
102-
"id=%d,x=%d,y=%d,w=%d,h=%d,cx=%d,cy=%d",
102+
"id=%d,x=%d,y=%d,w=%d,h=%d,cx=%d,cy=%d,score=%.2f",
103103
i,
104104
bbox.x,
105105
bbox.y,
106106
bbox.width,
107107
bbox.height,
108108
bbox.cx,
109-
bbox.cy
109+
bbox.cy,
110+
bbox.proba
110111
);
111112
client->print("id=");
112113
client->print(i);
@@ -122,6 +123,8 @@ namespace Eloquent {
122123
client->print(((float) bbox.cx) / EI_CLASSIFIER_INPUT_WIDTH);
123124
client->print("&cy=");
124125
client->print(((float) bbox.cy) / EI_CLASSIFIER_INPUT_HEIGHT);
126+
client->print("&score=");
127+
client->print(bbox.proba);
125128
client->print("|");
126129
});
127130

0 commit comments

Comments
 (0)