I am new to ESP32 CAM..I have just started using it.
So I am doing a project which involves accessing the pixel data directly. After going through the https://github.com/espressif/esp32-came ... p_camera.h I found that the pixel data is stored in a variable named buf.
I want to find to find the average value of pixel data, and thus need to access the pixel data.
Code: Select all
typedef struct {
uint8_t * buf; /*!< Pointer to the pixel data */
size_t len; /*!< Length of the buffer in bytes */
size_t width; /*!< Width of the buffer in pixels */
size_t height; /*!< Height of the buffer in pixels */
pixformat_t format; /*!< Format of the pixel data */
struct timeval timestamp; /*!< Timestamp since boot of the first DMA buffer of the frame */
} camera_fb_t;
Also the image is of dimensions 600x800 and is a colour image..(I took the photo of the image, stored it in an SDcard and viewed later...) which means the image is of dimensions 600x800x3 .This implies it should be a 3D array That means image data is a 3D array which is flattened into a 1D array.
Code: Select all
fb = esp_camera_fb_get();
Serial.println((String)"Length of the buffer in bytes: " + fb->len);
Code: Select all
int i,j;
long avgr=0,avgg=0,avgb=0;
for(i=0;i<600;i++)
{
for(j=0;j<800;j++)
avgr = avgr + *(fb->buf + (800*i + j)*3); //average of R channel
avgg = avgg + *(fb->buf + (800*i + j)*3 + 1); //average of G channel
avgb = avgb + *(fb->buf + (800*i + j)*3 + 2); //average of B channel
}
Can someone please tell me how exactly the pixel data is stored and how can i access all the values?
Also why is the length of buffer different for different images though they are are all of the same dimensions?
Thanks in Advance...