ESP-CAM: crop JPEG image on (ESP) device

alkorismus
Posts: 8
Joined: Tue Feb 26, 2019 1:55 am

ESP-CAM: crop JPEG image on (ESP) device

Postby alkorismus » Sat Feb 12, 2022 1:55 am

The block below shows what I like to have with ESP-CAM device.

Code: Select all

===============================================================
Inside ESP32 Device
-------------------

     JPEG                  JPEG     
 ------------         
|            |         ------------
|   fb>buf   |   =>   |    crop    |
| 400 x 296  |        | 400 x 225  |
|            |         ------------
 ------------         


... then, transmitt TRANSFORMED JPEG image (serial, wifi, bt)...
===============================================================
First, capture JPEG image.
Second, crop it, inside the ESP32
Then, send it to outside...

Constraint:
I am targeting the M5Stack UnitCam (ESP32 WROOM + ov2640), which DOES NOT have PSRAM!

Looks like there are functions to convert to BMP/RGB, which then can make CROP easier, then converting again to JPEG with the lower resolution... THE PROBLEM is NOT HAVING PSRAM to use...

So, the options seems to be a function that can take the JPEG buffer and directly "peek into" it skipping the unwanted slice of bits...

My goal here is to be able to "trim" down the ammount of image data BEFORE it is transmitted to the outside of the ESP device.

Trying to understand how JPEG works, so to make a little hack into the image data, I found the following tutorial:
https://yasoob.me/posts/understanding-a ... in-python/

...problem is, the code example it provides ONLY work for the sample image that it provides... giving errors when used with some other image captured by ESP32-Camera soft...
It looks like the JPEG format is not exactly 1 format which is defined... it has kind of "extensions/branchs" with different ways to read the pixel/bits...

So, my investigation into JPEG format was "paused" there, without having a clear idea about the standard and what is the difficulty involved to achive a crop function...

Question:
Does anyone knows any function on ESP32-CAMERA soft or any code created for the ESP32 that can do JPEG crop inside the ESP32, directly (and memory-economically) working on the image-buffer?

This is not a necessity, just a desired feature, so, I am hopping to find an easy and already done solution, otherwise I will leave things without crop, since it is working well...

Thanks all,
Valter

Who is online

Users browsing this forum: No registered users and 50 guests