Hi,
(sorry for repeat, I have posted this earlier on a wrong topic)
I am working on a project that captures a small picture (QQVGA 160x120) with an esp32s cam. Target is to have an array (160 x 120 or smaller) with a binary (=b/w) representation of the picture.
So my question is can you please hint me how to covert a small picture to bin array?
Thank you for your guidance!
just for illustration:
|1|1|1|1|0|1|1|1|
|1|1|1|0|0|1|1|1|
|1|1|0|1|0|1|1|1|
|1|1|1|1|0|1|1|1|
|1|1|1|1|0|1|1|1|
|1|1|1|1|0|1|1|1|
|1|1|1|1|0|1|1|1|
|1|1|0|0|0|0|0|1|
if you don't care about memory, a 160x120 byte 2D array is the direct answer. uint8_t image[160][120];
accessing a pixel is straightforward : image[x][y];
If you care about memory, as you are in B&W, you don't need a full byte to represent a pixel, you just need a bit. You could group 8 contiguous pixels in a line or a row (both 160 and 120 can be divided by 8) and use a smaller 2D array uint8_t image[160][15]; // here grouped 8 bits in the vertical axis
or uint8_t image[20][120]; // here grouped 8 bits in the horizontal axis
accessing the pixel in position (x,y) requires then a bit more work math. dividing by 8 to find the index, taking the modulo to find the bit and using bitRead() to extract that bit.
There is a great little utility called LCDAssistant. Google it to find.
Basically it will convert a bitmap into a hex array for you.
It might not be exactly what you are looking for, but it might provide an alternative approach to your problem.
thanks all. btw it is a 'he'. Any help is welcome but indeed I am working on code to convert the pic to bin array. Needs to be within the code not external sw. Thanks!
At the start of your code you have to define a config variable of type camera_config_t that you'll pass to the initialisation method
esp_err_t err = esp_camera_init(&config);
this is what the structure looks like:
there are two fields of importance for the format:
pixformat_t pixel_format; /*!< Format of the pixel data: PIXFORMAT_ + YUV422|GRAYSCALE|RGB565|JPEG */
framesize_t frame_size; /*!< Size of the output image: FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA */
so you would go for FRAMESIZE_QQVGA for the latter but as you can see BMP is not supported for the pixel_format but you have various RGB options
In the description BPP means Bit Per Pixel, so with PIXFORMAT_RGB888 you would get 8 bits (1 byte) for Red, 1 byte for Green and 1 byte for Blue and with PIXFORMAT_GRAYSCALE you would get 1 byte per pixel which would be 256 shades of grey.