I have a problem in my program and I haven't figured out how to fix it, so I'm calling on your enlightenment!
I am currently programming with an ESP32-CAM and trying to get an image in RGB888 format. As we cannot take the image directly in the desired format, the most obvious way is to take the image in JPEG format and then transform it into RGB888 format via the function fmt2rgb888().
I come to my problem: when I introduce a buf, let's say "_rgb888_buf" in the function, fmt2rgb888() returns TRUE to me and returns me the buf that I introduced to it with exactly the same value as when it goes in.
I created a little program a bit outside of my project to highlight the problem. I take a JPEG image, transform it to RGB888 via fmt2rgb888 (), then apply a filter to it that removes all green and red components at each pixel and then reshuffle the image as JPEG and send it to a web page to see the result.
- void startCameraServer(){
- httpd_config_t config = HTTPD_DEFAULT_CONFIG();
- config.server_port = 80;
- config.stack_size = 15000;
- httpd_uri_t index_uri = {
- .uri = "/",
- .method = HTTP_GET,
- .handler = capture_handler,
- .user_ctx = NULL
- };
- static esp_err_t capture_handler(httpd_req_t *req) {
- camera_fb_t *fb = NULL;
- esp_err_t res = ESP_OK;
- size_t _jpg_buf_len = 0;
- uint8_t * _jpg_buf = NULL, * _rgb888_buf = NULL;
- res = httpd_resp_set_type(req, "image/jpeg");
- if (res == ESP_OK)
- {
- res = httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=image.jpg"); //capture
- }
- if (res == ESP_OK) {
- ESP_LOGI(TAG, "Take a picture");
- fb = esp_camera_fb_get();
- if (!fb)
- {
- ESP_LOGE(TAG, "Camera capture failed");
- httpd_resp_send_500(req);
- return ESP_FAIL;
- } else {
- Serial.println("we came by [2]");
- if(!fmt2rgb888((const uint8_t *) fb->buf,fb->len,fb->format, _rgb888_buf)) Serial.println("fmt2rgb888 function failed");
- else {
- if(_rgb888_buf == NULL) Serial.println("Why _rgb888_buf is NULL ????");
- Serial.println("we came by [3]");
- _rgb888_buf = photoshop_with_rgb888(_rgb888_buf, 600, 800); //We apply a Blue Filter on image
- if(!fmt2jpg(_rgb888_buf, fb->height*fb->width*3, fb->width,fb->height, PIXFORMAT_RGB888, 15, &_jpg_buf, &_jpg_buf_len)) Serial.println("fmt2jpg function failed");
- res = httpd_resp_send(req, (const char *)_jpg_buf, _jpg_buf_len);//Send the picture to the web page
- free(_jpg_buf);
- _jpg_buf = NULL;
- _jpg_buf_len = 0;
- esp_camera_fb_return(fb);
- }
- }
- }
- return res;
- }
- //Apply a Blue Filter on an image
- uint8_t* photoshop_with_rgb888(uint8_t *buf, size_t height, size_t width)
- {
- for (int y = 0; y < height; y++)
- {
- for (int x = 0; x < width; x++)
- {
- uint32_t offset = (y * width + x) * 3; //we are in the 'offset' pixel.
- Serial.println("we came by [4]");
- //I go in 1st byte of the pixel
- buf[offset] = buf[offset] & 0b11111111; //I didn't change the byte for Blue
- Serial.println("we came by [5]");
- //I go in 2nd byte of the pixel
- buf[offset + 1] = buf[offset + 1] & 0b00000000; //I change the byte for green to 0
- Serial.println("we didn't come by [6]");
- //I go in 3rd byte of the pixel
- buf[offset + 2] = buf[offset + 2] & 0b00000000; //I change the byte for red to 0
- }
- }
- return buf;
- }
We see that it entered the test "_rgb888_buf == NULL" while fmt2rgb888 () returned TRUE and we see that it crashed when it tried to change the byte of the green component of the pixel (Normal seen that the buf = NULL).WiFi connected
Camera Stream Ready! Go to: http://192.168.1.45
we came by [2]
Why _rgb888_buf is NULL ????
we came by [3]
we came by [4]
we came by [5]
Guru Meditation Error: Core 0 panic'ed (StoreProhibited). Exception was unhandled.
If anyone has any idea why fmt2rgb888 isn't working, I'm interested!