Skip to content

Commit

Permalink
Fix RGB565 converter
Browse files Browse the repository at this point in the history
  • Loading branch information
cnadler86 committed Nov 17, 2024
1 parent eff3237 commit 7d52f87
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,25 +246,25 @@ If you experience problems, visit [MicroPython external C modules](https://docs.

## FPS benchmark

I didn't use a calibrated osziloscope, but here is a benchmark with my ESP32S3 (GrabMode=LATEST).
I didn't use a calibrated osziloscope, but here is a benchmark with my ESP32S3 (GrabMode=LATEST, fb_count = 1, jpeg_quality=85%).
Using fb_count=2 doubles the FPS for JPEG. This might also aplly for other PixelFormats.

| Frame Size | GRAYSCALE | RGB565 | YUV422 | JPEG | JPEG (fb = 2) |
|------------|-----------|--------|--------|--------|---------------|
| R96X96 | 12.5 | 12.5 | 12.5 | No img | No img |
| QQVGA | 12.5 | 12.5 | 12.5 | 25 | 50 |
| QCIF | 11 | 11 | 11.5 | 25 | 50 |
| HQVGA | 12.5 | 12.5 | 12.5 | 25 | 50 |
| R240X240 | 12 | 12.5 | 11.5 | 25 | 50 |
| QVGA | 12 | 11 | 12 | 25 | 50 |
| CIF | 12.5 | No img | No img | 6 | 12.5 |
| HVGA | 2.5 | 3 | 2.5 | 12.5 | 25 |
| VGA | 3 | 3 | 3 | 12.5 | 25 |
| SVGA | 3 | 3 | 3 | 12.5 | 25 |
| XGA | No img | No img | No img | 6 | 12.5 |
| HD | No img | No img | No img | 6 | 12.5 |
| SXGA | 2 | 2 | 2 | 6 | 12.5 |
| UXGA | No img | No img | No img | 6 | 12.5 |
| Frame Size | GRAYSCALE | RGB565 | YUV422 | JPEG | JPEG -> RGB565 | JPEG -> RGB888 | JPEG (fb = 2) |
|------------|-----------|--------|--------|--------|----------------|----------------|---------------|
| R96X96 | 12.5 | 12.5 | 12.5 | No img | No img | No img | No img |
| QQVGA | 12.5 | 12.5 | 12.5 | 25 | 25 | 25 | 50 |
| QCIF | 11 | 11 | 11.5 | 25 | 25 | 25 | 50 |
| HQVGA | 12.5 | 12.5 | 12.5 | 25 | 16.7 | 16.7 | 50 |
| R240X240 | 12 | 12.5 | 11.5 | 25 | 16.7 | 12.5 | 50 |
| QVGA | 12 | 11 | 12 | 25 | 12.5 | 12.5 | 50 |
| CIF | 12.5 | No img | No img | 6 | 1.6 | 1.6 | 12.5 |
| HVGA | 2.5 | 3 | 2.5 | 12.5 | 6.3 | 6.3 | 25 |
| VGA | 3 | 3 | 3 | 12.5 | 3.6 | 3.6 | 25 |
| SVGA | 3 | 3 | 3 | 12.5 | 2.8 | 2.5 | 25 |
| XGA | No img | No img | No img | 6 | 1.6 | 1.6 | 12.5 |
| HD | No img | No img | No img | 6 | 1.4 | 1.3 | 12.5 |
| SXGA | 2 | 2 | 2 | 6 | 1 | 1 | 12.5 |
| UXGA | No img | No img | No img | 6 | 0.7 | 0.7 | 12.5 |

## Future Plans

Expand Down
21 changes: 11 additions & 10 deletions examples/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
gc.enable()

def measure_fps(duration=2):
start_time = time.time()
while time.time() - start_time < 0.5:
start_time = time.ticks_ms()
while time.ticks_ms() - start_time < 500:
cam.capture()

start_time = time.time()
start_time = time.ticks_ms()
frame_count = 0

while time.time() - start_time < duration:
cam.capture()
frame_count += 1
while time.ticks_ms() - start_time < duration*1000:
img = cam.capture()
if img:
frame_count += 1

end_time = time.time()
fps = frame_count / (end_time - start_time)
return fps
end_time = time.ticks_ms()
fps = frame_count / (end_time - start_time) * 1000
return round(fps,1)

def print_summary_table(results, cam):
print(f"\nBenchmark {os.uname().machine} with {cam.get_sensor_name()}, GrabMode: {cam.get_grab_mode()}:")
Expand Down Expand Up @@ -78,7 +79,7 @@ def print_summary_table(results, cam):
print('Set', p, f,f'fb={fb}',':')

try:
cam.reconfigure(frame_size=f_value)
cam.set_frame_size(f_value)
time.sleep_ms(10)
img = cam.capture()

Expand Down
6 changes: 6 additions & 0 deletions src/modcamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ mp_obj_t mp_camera_hal_capture(mp_camera_obj_t *self, int8_t out_format) {
}

case PIXFORMAT_RGB565:
out_len = self->captured_buffer->width * self->captured_buffer->height * 2;
out_buf = (uint8_t *)malloc(out_len);
if (!out_buf) {
ESP_LOGE(TAG, "out_buf malloc failed");
return mp_const_none;
}
if(self->camera_config.pixel_format == PIXFORMAT_JPEG){
if (jpg2rgb565(self->captured_buffer->buf, self->captured_buffer->len, out_buf, JPG_SCALE_NONE)) {
esp_camera_fb_return(self->captured_buffer);
Expand Down

0 comments on commit 7d52f87

Please sign in to comment.