kopia lustrzana https://github.com/alanesq/esp32cam-demo
Add files via upload
rodzic
983be625a6
commit
422783b6e2
|
@ -49,10 +49,7 @@
|
||||||
|
|
||||||
// Camera related
|
// Camera related
|
||||||
const bool flashRequired = 1; // If flash to be used when capturing image (1 = yes)
|
const bool flashRequired = 1; // If flash to be used when capturing image (1 = yes)
|
||||||
const framesize_t FRAME_SIZE_IMAGE = FRAMESIZE_VGA;
|
const framesize_t FRAME_SIZE_IMAGE = FRAMESIZE_VGA; // Image resolution:
|
||||||
const int I_WIDTH = 640; // image dimensions (used for converting image to rgb)
|
|
||||||
const int I_HEIGHT = 480;
|
|
||||||
// Image resolution:
|
|
||||||
// default = "const framesize_t FRAME_SIZE_IMAGE = FRAMESIZE_XGA"
|
// default = "const framesize_t FRAME_SIZE_IMAGE = FRAMESIZE_XGA"
|
||||||
// 160x120 (QQVGA), 128x160 (QQVGA2), 176x144 (QCIF), 240x176 (HQVGA),
|
// 160x120 (QQVGA), 128x160 (QQVGA2), 176x144 (QCIF), 240x176 (HQVGA),
|
||||||
// 320x240 (QVGA), 400x296 (CIF), 640x480 (VGA, default), 800x600 (SVGA),
|
// 320x240 (QVGA), 400x296 (CIF), 640x480 (VGA, default), 800x600 (SVGA),
|
||||||
|
@ -731,13 +728,14 @@ void readRGBImage() {
|
||||||
camera_fb_t * fb = NULL;
|
camera_fb_t * fb = NULL;
|
||||||
fb = esp_camera_fb_get();
|
fb = esp_camera_fb_get();
|
||||||
if (!fb) tReply+=" -Error capturing image from camera- ";
|
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
|
// allocate memory to store rgb data in psram
|
||||||
if (!psramFound()) tReply+=" -Error no psram found- ";
|
if (!psramFound()) tReply+=" -Error no psram found- ";
|
||||||
void *ptrVal = NULL;
|
void *ptrVal = NULL;
|
||||||
uint32_t ARRAY_LENGTH = I_WIDTH * I_HEIGHT * 3; // number of pixels in the jpg image x 3
|
uint32_t ARRAY_LENGTH = fb->width * fb->height * 3; // number of pixels in the jpg image x 3
|
||||||
bool memRes = ptrVal = heap_caps_malloc(ARRAY_LENGTH, MALLOC_CAP_SPIRAM);
|
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
|
||||||
if (!memRes) tReply+=" -Error allocating memory for RGB data- ";
|
ptrVal = heap_caps_malloc(ARRAY_LENGTH, MALLOC_CAP_SPIRAM);
|
||||||
uint8_t *rgb = (uint8_t *)ptrVal;
|
uint8_t *rgb = (uint8_t *)ptrVal;
|
||||||
|
|
||||||
// convert jpg to rgb (store in an array 'rgb')
|
// convert jpg to rgb (store in an array 'rgb')
|
||||||
|
@ -747,8 +745,8 @@ void readRGBImage() {
|
||||||
// display some of the resulting data
|
// display some of the resulting data
|
||||||
for (uint32_t i = 0; i < resultsToShow; i++) {
|
for (uint32_t i = 0; i < resultsToShow; i++) {
|
||||||
// // x and y coordinate of the pixel
|
// // x and y coordinate of the pixel
|
||||||
// uint16_t x = i % I_WIDTH;
|
// uint16_t x = i % fb->width;
|
||||||
// uint16_t y = floor(i / I_WIDTH);
|
// uint16_t y = floor(i / fb->width);
|
||||||
if (i%3 == 0) tReply+="B";
|
if (i%3 == 0) tReply+="B";
|
||||||
else if (i%3 == 1) tReply+="G";
|
else if (i%3 == 1) tReply+="G";
|
||||||
else if (i%3 == 2) tReply+="R";
|
else if (i%3 == 2) tReply+="R";
|
||||||
|
@ -764,9 +762,9 @@ void readRGBImage() {
|
||||||
aGreen+=rgb[i+1];
|
aGreen+=rgb[i+1];
|
||||||
aRed+=rgb[i+2];
|
aRed+=rgb[i+2];
|
||||||
}
|
}
|
||||||
aRed = aRed / (I_WIDTH * I_HEIGHT);
|
aRed = aRed / (fb->width * fb->height);
|
||||||
aGreen = aGreen / (I_WIDTH * I_HEIGHT);
|
aGreen = aGreen / (fb->width * fb->height);
|
||||||
aBlue = aBlue / (I_WIDTH * I_HEIGHT);
|
aBlue = aBlue / (fb->width * fb->height);
|
||||||
tReply+=" Average Red = " + String(aRed);
|
tReply+=" Average Red = " + String(aRed);
|
||||||
tReply+=", Average Green = " + String(aGreen);
|
tReply+=", Average Green = " + String(aGreen);
|
||||||
tReply+=", Average Blue = " + String(aBlue);
|
tReply+=", Average Blue = " + String(aBlue);
|
||||||
|
|
Ładowanie…
Reference in New Issue