how to access frame buffer data directly?

Posts: 1
Joined: Mon Apr 05, 2021 7:01 am

how to access frame buffer data directly?

Postby Faf_esp » Mon Apr 05, 2021 7:34 am


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 ... 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;
This code snippet shows that data is stored as a 1D array. So i am doing *(fb->buf) to get the pixel data. But this gives only one value.
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);
I got the length of buf from the above code..

Code: Select all

int i,j;
long avgr=0,avgg=0,avgb=0;
    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
I am doing this to get average data (Considering the dimensions of image are 600x800x3). But this gives me a "Guru meditation error." I am guessing the problem is with the way I am trying to access pixel data :?

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... :D

Posts: 4574
Joined: Thu Nov 26, 2015 4:08 am

Re: how to access frame buffer data directly?

Postby ESP_Sprite » Tue Apr 06, 2021 4:08 am

You make a lot of assumptions... does fb->len indeed read 1440000? Does fb->format indicate this is rgb24 data, and not for instance a JPEG?

Who is online

Users browsing this forum: samca208 and 58 guests