Skip to content

Commit 0a0698c

Browse files
committed
Performance improvements and image conversion improved and tested
1 parent 34ee0fa commit 0a0698c

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,22 @@ Arguments for capture
108108

109109
### Convert image to another format
110110

111-
You can either convert the image with the capture method directly passing the desired output format:
111+
You can either convert the image with the `capture` method directly passing the desired output format:
112112
```python
113113
img_rgb888 = cam.capture(PixelFormat.RGB888) #capture image as configured (e.g. JPEG), convert it to RGB888 and return the converted image
114114
```
115-
Or you can first capture the image and then convert the captured image to the desired PixelFormat with the convert method.
116-
Doing so you can have both, the raw and the converted image.
115+
Or you can first capture the image and then convert it to the desired PixelFormat with the `convert` method.
116+
Doing so you can have both, the captured and the converted image. Note that more memory will be used.
117117
```python
118118
img = cam.capture()
119119
img_rgb888 = cam.convert(PixelFormat.RGB888) #converts the last captured image to RGB888 and returns the converted image
120120
```
121121

122+
Convertion supported
123+
- from JPEG to RGB565
124+
- to RGB888 in general
125+
- to JPEG in gerenal (use the `set_quality` method to set the desired JPEG quality)
126+
122127
### Camera reconfiguration
123128

124129
```python
@@ -229,12 +234,12 @@ Example for Xiao sense:
229234
#define MICROPY_CAMERA_PIN_XCLK (10)
230235
#define MICROPY_CAMERA_PIN_PWDN (-1)
231236
#define MICROPY_CAMERA_PIN_RESET (-1)
232-
#define MICROPY_CAMERA_PIN_SIOD (40) // SDA
233-
#define MICROPY_CAMERA_PIN_SIOC (39) // SCL
237+
#define MICROPY_CAMERA_PIN_SIOD (40) // SDA
238+
#define MICROPY_CAMERA_PIN_SIOC (39) // SCL
234239
#define MICROPY_CAMERA_XCLK_FREQ (20000000) // Frequencies are normally either 10 MHz or 20 MHz
235-
#define MICROPY_CAMERA_FB_COUNT (2) // The value is between 1 (slow) and 2 (fast, but more load on CPU and more ram usage)
236-
#define MICROPY_CAMERA_JPEG_QUALITY (85) // Quality of JPEG output in percent. Higher means higher quality.
237-
#define MICROPY_CAMERA_GRAB_MODE (1) // 0=WHEN_EMPTY (might have old data, but less resources), 1=LATEST (best, but more resources)
240+
#define MICROPY_CAMERA_FB_COUNT (2) // The value is between 1 (slow) and 2 (fast, but more load on CPU and more ram usage)
241+
#define MICROPY_CAMERA_JPEG_QUALITY (85) // Quality of JPEG output in percent. Higher means higher quality.
242+
#define MICROPY_CAMERA_GRAB_MODE (1) // 0=WHEN_EMPTY (might have old data, but less resources), 1=LATEST (best, but more resources)
238243

239244
```
240245
#### Customize additional camera settings
@@ -265,7 +270,7 @@ If you experience problems, visit [MicroPython external C modules](https://docs.
265270

266271
## FPS benchmark
267272

268-
I didn't use a calibrated osziloscope, but here is a benchmark with my ESP32S3 (GrabMode=LATEST, fb_count = 1, jpeg_quality=85%).
273+
I didn't use a calibrated osziloscope, but here is a benchmark with my ESP32S3 (GrabMode=LATEST, fb_count = 1, jpeg_quality=85%) and OV2640.
269274
Using fb_count=2 theoretically can double the FPS (see JPEG with fb_count=2). This might also aplly for other PixelFormats.
270275

271276
| Frame Size | GRAYSCALE | RGB565 | YUV422 | JPEG | JPEG -> RGB565 | JPEG -> RGB888 | JPEG (fb=2) |
@@ -275,8 +280,8 @@ Using fb_count=2 theoretically can double the FPS (see JPEG with fb_count=2). Th
275280
| QCIF | 11 | 11 | 11.5 | 25 | 25 | 25 | 50 |
276281
| HQVGA | 12.5 | 12.5 | 12.5 | 25 | 16.7 | 16.7 | 50 |
277282
| R240X240 | 12.5 | 12.5 | 11.5 | 25 | 16.7 | 12.5 | 50 |
278-
| QVGA | 12 | 11 | 12 | 25 | 12.5 | 12.5 | 50 |
279-
| CIF | 12.5 | No img | No img | 6.3 | 1.6 | 1.6 | 12.5 |
283+
| QVGA | 12 | 11 | 12 | 25 | 25 | 25 | 50 |
284+
| CIF | 12.5 | No img | No img | 6.3 | 8.3 | 8.3 | 12.5 |
280285
| HVGA | 3 | 3 | 2.5 | 12.5 | 6.3 | 6.3 | 25 |
281286
| VGA | 3 | 3 | 3 | 12.5 | 3.6 | 3.6 | 25 |
282287
| SVGA | 3 | 3 | 3 | 12.5 | 2.8 | 2.5 | 25 |

src/modcamera.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,10 @@ void mp_camera_hal_reconfigure(mp_camera_obj_t *self, mp_camera_framesize_t fram
214214
ESP_LOGI(TAG, "Camera reconfigured successfully");
215215
}
216216

217-
static bool ensure_buffer(mp_camera_obj_t self, size_t req_len) {
217+
static bool ensure_buffer(mp_camera_obj_t *self, size_t req_len) {
218218
if (self->converted_buffer.len == req_len) {
219219
return true;
220220
}
221-
222221
if (self->converted_buffer.len > 0 || self->converted_buffer.buf) {
223222
free(self->converted_buffer.buf);
224223
}
@@ -232,7 +231,7 @@ static bool ensure_buffer(mp_camera_obj_t self, size_t req_len) {
232231
return true;
233232
}
234233

235-
static bool mp_camera_convert(mp_camera_obj_t self, mp_camera_pixformat_t out_format) {
234+
static bool mp_camera_convert(mp_camera_obj_t *self, mp_camera_pixformat_t out_format) {
236235
ESP_LOGI(TAG, "Converting image to pixel format: %d", out_format);
237236

238237
switch (out_format) {
@@ -308,7 +307,6 @@ mp_obj_t mp_camera_hal_capture(mp_camera_obj_t *self, int8_t out_format) {
308307
self->converted_buffer.buf = NULL;
309308
self->converted_buffer.len = 0;
310309
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to convert image to BMP"));
311-
return mp_const_none;
312310
}
313311
}
314312
} // mp_camera_hal_capture

0 commit comments

Comments
 (0)