Hi,filolipe wrote: ↑Tue Nov 10, 2020 12:42 pmHello, I am carrying out a project in which I apply a beam of light over the camera and I would like to take the values in rgb of pixel face, I would just like that, without all those other features of the ESP32 Cam, I am very lay in programming, will it be that could someone help me with this.
I have been having a play with this myself recently (i.e. reading RGB data) and I think I have figured out how to access the RGB data of an image without it getting too complicated.
I have included it in a sketch here which may be of interest: https://github.com/alanesq/esp32cam-demo
if you look at the procedure 'readRGBImage()' this captures a live image, converts it to RGB then shows the first few bytes of data via the serial port.
I have not tested it but this should work with all but the highest resolution camera images as the RGB data is stored in the 4mb psram chip on the esp32cam modules (the highest resolution would require more memory than this to store the RGB data).
BTW-You can check how much free space there is with the command: Serial.println(heap_caps_get_free_size( MALLOC_CAP_SPIRAM));
The relevant code:
- uint32_t resultsToShow = 50; // how much data to display
- String tReply = "LIVE IMAGE AS RGB DATA: "; // reply to send to web client and serial port
- // capture live image (jpg)
- camera_fb_t * fb = NULL;
- fb = esp_camera_fb_get();
- if (!fb) tReply+=" -Error capturing image from camera- ";
- tReply+="(Image resolution=" + String(fb->width) + "x" + String(fb->height) + ")"; // display image resolution
- // allocate memory to store rgb data in psram
- if (!psramFound()) tReply+=" -Error no psram found- ";
- void *ptrVal = NULL;
- uint32_t ARRAY_LENGTH = fb->width * fb->height * 3; // number of pixels in the jpg image x 3
- if (heap_caps_get_free_size( MALLOC_CAP_SPIRAM) < ARRAY_LENGTH) tReply+=" -Error not enough free psram to store rgb data- "; // check free memory in psram
- ptrVal = heap_caps_malloc(ARRAY_LENGTH, MALLOC_CAP_SPIRAM);
- uint8_t *rgb = (uint8_t *)ptrVal;
- // convert jpg to rgb (store in an array 'rgb')
- bool jpeg_converted = fmt2rgb888(fb->buf, fb->len, PIXFORMAT_JPEG, rgb);
- if (!jpeg_converted) tReply+=" -Error converting image to RGB- ";
- // display some of the resulting data
- for (uint32_t i = 0; i < resultsToShow; i++) {
- // // x and y coordinate of the pixel
- // uint16_t x = i % fb->width;
- // uint16_t y = floor(i / fb->width);
- if (i%3 == 0) tReply+="B";
- else if (i%3 == 1) tReply+="G";
- else if (i%3 == 2) tReply+="R";
- tReply+= String(rgb[i]) + ",";
- }
- // free up memory
- esp_camera_fb_return(fb);
- heap_caps_free(ptrVal);
- Serial.println(tReply);