ESP32-CAM buffer


When I initialize the camera I use this:

#include "esp_camera.h"

bool initCamera(){
    Serial.print("Iniciando Cámara ...");
    camera_config_t config;
    config.ledc_channel = LEDC_CHANNEL_0;
    config.ledc_timer = LEDC_TIMER_0;
    config.pin_d0 = Y2_GPIO_NUM;

    config.xclk_freq_hz = 20000000;
    config.pixel_format = PIXFORMAT_JPEG;
    config.frame_size = FRAMESIZE_XGA;
    config.jpeg_quality = 8;
    config.fb_count = 1;
    config.grab_mode = CAMERA_GRAB_LATEST; <<<<<<< 

    // camera init
    esp_err_t err = esp_camera_init(&config);
    if (err != ESP_OK){
        Serial.printf("... error 0x%x", err);
        return false;

    sensor_t *s = esp_camera_sensor_get();
    Serial.println("... OK");
    CAMARA_OK = true;
    return true;

But when I ask for a capture:

static esp_err_t capture_handler(httpd_req_t *req){


    camera_fb_t *fb = NULL;
    esp_err_t res = ESP_OK;

    fb = esp_camera_fb_get();

    if (!fb){

        Serial.println("Camera capture failed");
        return ESP_FAIL;

the image it shows me is from before, it takes a delayed capture.

I want that when I ask for a capture, it gives me the one from that moment, not the one stored in the buffer

>Solution :

I have the same problem, I’ve been looking for the solution for days and although it seems to be fine, it doesn’t do what it’s supposed to do.
At the moment I am using this "trick":

fb = esp_camera_fb_get();
fb = esp_camera_fb_get();

I ask for a capture, I discard it and then I ask for another one, which is current

Leave a ReplyCancel reply