diff --git a/examples/benchmark.py b/examples/benchmark.py index 6dbcd81..806a204 100644 --- a/examples/benchmark.py +++ b/examples/benchmark.py @@ -21,23 +21,32 @@ def measure_fps(duration=2): return fps def print_summary_table(results, cam): - print(f"\nBenchmark {os.uname().machine} with {cam.get_sensor_name()}, fb_count: {cam.get_fb_count()}, GrabMode: {cam.get_grab_mode()}:") - - pixel_formats = list(results.keys()) - print(f"{'Frame Size':<15}", end="") - for p in pixel_formats: - print(f"{p:<15}", end="") - print() + print(f"\nBenchmark {os.uname().machine} with {cam.get_sensor_name()}, GrabMode: {cam.get_grab_mode()}:") + fb_counts = sorted(results.keys()) frame_size_names = {getattr(FrameSize, f): f for f in dir(FrameSize) if not f.startswith('_')} - frame_sizes = list(next(iter(results.values())).keys()) + + header_row = f"{'Frame Size':<15}" + sub_header_row = " " * 15 + + for fb in fb_counts: + for p in results[fb].keys(): + header_row += f"{'fb_count ' + str(fb):<15}" + sub_header_row += f"{p:<15}" + + print(header_row) + print(sub_header_row) + + frame_sizes = list(next(iter(next(iter(results.values())).values())).keys()) for f in frame_sizes: frame_size_name = frame_size_names.get(f, str(f)) print(f"{frame_size_name:<15}", end="") - for p in pixel_formats: - fps = results[p].get(f, "N/A") - print(f"{fps:<15}", end="") + + for fb in fb_counts: + for p in results[fb].keys(): + fps = results[fb][p].get(f, "N/A") + print(f"{fps:<15}", end="") print() if __name__ == "__main__": @@ -45,52 +54,55 @@ def print_summary_table(results, cam): results = {} try: - for p in dir(PixelFormat): - if not p.startswith('_'): - p_value = getattr(PixelFormat, p) - if p_value == PixelFormat.RGB888 and cam.get_sensor_name() == "OV2640": - continue - try: - cam.reconfigure(pixel_format=p_value) - results[p] = {} - except Exception as e: - print('ERR:', e) - continue + for fb in [1, 2]: + cam.reconfigure(fb_count=fb) + results[fb] = {} + for p in dir(PixelFormat): + if not p.startswith('_'): + p_value = getattr(PixelFormat, p) + if (p_value == PixelFormat.RGB888 and cam.get_sensor_name() == "OV2640") or (p_value != PixelFormat.JPEG and fb > 1): + continue + try: + cam.reconfigure(pixel_format=p_value) + results[fb][p] = {} + except Exception as e: + print('ERR:', e) + continue - for f in dir(FrameSize): - if not f.startswith('_'): - f_value = getattr(FrameSize, f) - if f_value > cam.get_max_frame_size(): - continue - gc.collect() - print('Set', p, f, ':') - - try: - cam.reconfigure(frame_size=f_value) - time.sleep_ms(10) - img = cam.capture() - - if img: - print('---> Image size:', len(img)) - fps = measure_fps(2) - print(f"---> FPS: {fps}") - results[p][f_value] = fps # FPS in Dictionary speichern - else: - print('No image captured') - results[p][f_value] = 'No image' - - print(f"---> Free Memory: {gc.mem_free()}") - except Exception as e: - print('ERR:', e) - results[p][f_value] = 'ERR' - finally: - time.sleep_ms(250) + for f in dir(FrameSize): + if not f.startswith('_'): + f_value = getattr(FrameSize, f) + if f_value > cam.get_max_frame_size(): + continue gc.collect() - print('') + print('Set', p, f,f'fb={fb}',':') + + try: + cam.reconfigure(frame_size=f_value) + time.sleep_ms(10) + img = cam.capture() + + if img: + print('---> Image size:', len(img)) + fps = measure_fps(2) + print(f"---> FPS: {fps}") + results[fb][p][f_value] = fps + else: + print('No image captured') + results[fb][p][f_value] = 'No img' + + print(f"---> Free Memory: {gc.mem_free()}") + except Exception as e: + print('ERR:', e) + results[fb][p][f_value] = 'ERR' + finally: + time.sleep_ms(250) + gc.collect() + print('') except KeyboardInterrupt: print("\nScript interrupted by user.") finally: - print_summary_table(results,cam) # Tabelle am Ende ausgeben + print_summary_table(results, cam) cam.deinit() diff --git a/src/modcamera.c b/src/modcamera.c index bff5f9f..041554b 100644 --- a/src/modcamera.c +++ b/src/modcamera.c @@ -155,10 +155,11 @@ void mp_camera_hal_init(mp_camera_obj_t *self) { if (self->initialized) { return; } - if (self->camera_config.fb_count > 1 && self->camera_config.pixel_format != PIXFORMAT_JPEG) { - mp_warning(NULL, "It is recomended to use a frame buffer size of 1 for non-JPEG pixel format"); - } - + #ifndef CONFIG_IDF_TARGET_ESP32S3 + if (self->camera_config.fb_count > 1 && self->camera_config.pixel_format != PIXFORMAT_JPEG) { + mp_warning(NULL, "It is recomended to use a frame buffer size of 1 for non-JPEG pixel format"); + } + #endif ESP_LOGI(TAG, "Initializing camera"); // Correct the quality before it is passed to esp32 driver and then "undo" the correction in the camera_config int8_t api_jpeg_quality = self->camera_config.jpeg_quality; @@ -217,9 +218,9 @@ void mp_camera_hal_reconfigure(mp_camera_obj_t *self, mp_camera_framesize_t fram self->camera_config.grab_mode = grab_mode; } - if (fb_count > 3) { - self->camera_config.fb_count = 3; - mp_warning(NULL, "Frame buffer size limited to 3"); + if (fb_count > 2) { + self->camera_config.fb_count = 2; + mp_warning(NULL, "Frame buffer size limited to 2"); } else if (fb_count < 1) { self->camera_config.fb_count = 1; mp_warning(NULL, "Set to min frame buffer size of 1");