Page 1 of 1

BMP image not saved as BMP file

Posted: Sun Sep 20, 2020 8:54 pm
by RogerInHawaii
BMP image not saved as BMP file


I'm grabbing an image from the camera in PIXFORMAT_RGB888 and FRAMESIZE_UXGA which makes it 1600x1200.

The call to esp_camera_fb_get() returns without error and I successfully save it to a file on the SD card with .BMP as the file extension.

I move the SD card over to my computer and bring the file up in Windows Explorer. The preview plane in Windows Explorer shows the picture and it looks to be about the right size image, i.e. about 1600X1200. But I see that the actual size of the file is only about 48KB. How can that be? A bitmap image of that size should be around 5.5 MEGABYTES!! ??

I bring the file up in my paint program and it opens up just fine. It shows that the image size is indeed 1600X1200. I use the program's "Save As" function to save it out as a new file and select to do it in the BMP format (even though it ought to already be in that format). It does the save, and when I look at that newly saved file in Windows Explorer it has a size of about 5.5 MEGABYTES, which is what I had expected of the original image file.

I go back to Windows Explorer and change the extension of the original file from BMP to JPG and then open that newly-named file in my paint program. It opens and displays just fine, still showing the 1600X1200 image. It SEEMS that my paint program doesn't bother to look at the extension on the file name but rather opens up the file and figures out from some header data what the format is.

MY CONCLUSION

Even though I selected to have the ESP32-CAM camera create an image at PIXFORMAT_RGB888 and FRAMESIZE_UXGA, what it actually created was a PIXFORMAT_JPEG image.

WHAT?? WHY?? HOW??

And how do I get it to actually grab the image in PIXFORMAT_RGB888?

I had initially come across notes on various forums that the "best way" to get a bitmap version is to first grab a JPG version and use the JPG-to-BMP function. But my attempts at doing that showed that it only worked for really small images and caused memory allocation failures for medium and large images. I concluded that the problem was that the ESP32-CAM didn't have enough memory to hold BOTH the original PIXFORMAT_JPEG image AND the intended PIXFORMAT_RGB888.

That's when I resorted to trying to simply grab the image initially in the PIXFORMAT_RGB888 (which would seem to be the most sensible approach and not have to do some JPGtoBMP conversion). And it SEEMED to work, even at the maximum image size. But then I realized it wasn't actually in the PIXFORMAT_RGB888 but rather in the PIXFORMAT_JPEG!!

Why is it defaulting to PIXFORMAT_JPEG when I specifically tell it I want PIXFORMAT_RGB888. Why doesn't it, at the very least, TELL ME, via a posting out to the serial monitor, that it's doing that?

WHY NOT ENOUGH MEMORY

And I have to wonder why the ESP32-CAM wasn't built to have enough memory to handle any and all combinations of PIXFORMATs and FRAMESIZEs.