Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve jpeg size estimate #26

Open
jepler opened this issue Dec 12, 2023 · 5 comments
Open

improve jpeg size estimate #26

jepler opened this issue Dec 12, 2023 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@jepler
Copy link
Member

jepler commented Dec 12, 2023

The jpeg size estimate in capture_buffer_size is causing folks trouble:

        if self.colorspace == OV5640_COLOR_JPEG:
            return self.width * self.height // self.quality

replace it with a better heuristic after gathering information.

note to users affected by this: Instead of using capture_buffer_size in jpeg mode, manually determine the size for your quality & resolution settings. When this value is too small, the capture routine returns None in jpeg mode.

@jepler
Copy link
Member Author

jepler commented Dec 12, 2023

espressif's esp32-camera uses width * height / 5 regardless of quality level.

@jmangum
Copy link

jmangum commented Dec 13, 2023

Confirming that setting the size of the capture buffer to cam.capture_buffer_size does for many settings of cam.quality truncate the buf = bytearray(cam.capture_buffer_size) such that the end-of-image (EOI) bit is missing, and cam.capture(buf) returns None rather than a memoryview jpeg. As noted, key is to set the size of buf large enough. After quite a bit of experimentation, where I am capturing images of a wide range of scenery, so far it appears that using esperssif's esp32-camera value of cam.width*cam.height/5 (perhaps this is supposed to be a floor divide, or //5?) works well. Should also note that I am using a cam.quality = 10, as I found that it reduces capture jpeg file sizes by about a factor-of-two while maintaining good image quality. Will deploy my remote camera system with this setting and see how it goes.

@jepler
Copy link
Member Author

jepler commented Dec 14, 2023

(the quoted code was "C" code in which "/" behaves similar to Python floor division "//" when the arguments are of integer type)

@jmangum
Copy link

jmangum commented Dec 14, 2023

Makes sense that the correct python usage should be floor division (//).

@jerryneedell
Copy link

FYI -- cam.width * cam.height // 5 seems to work much better for me as well.

@jepler jepler added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants