There doesn't seem to be a function for actually triggering a "capture" in the camera so I keep thinking that "getting the frame buffer" means I'm getting a pointer to the image that was already captured by the camera. And if it is already being captured then I also assume the camera is continuously taking stills in the background after I called esp_camera_init().
The main reason I'm asking this question is because I set-up a video stream using ESP-IDF HTTP Server and I also wanted to obtain the camera frames myself in the Arduino loop function to process video frames independently of the server. So I have two separate calls to esp_camera_fb_get() and I want to know if there's some kind of performance consequence of it. I also encounter this error or warning when I run my code with these two calls "[E][camera.c:1474] esp_camera_fb_get(): Failed to get the frame on time!"
Here is my code where I call esp_camera_fb_get() twice in my project:
Code: Select all
void loop() {
fb = esp_camera_fb_get();
esp_camera_fb_return(fb);
fb = NULL;
}
Code: Select all
static esp_err_t stream_handler(httpd_req_t *req) {
esp_err_t res = ESP_OK;
char * part_buf[64];
camera_fb_t * fb = NULL;
res = httpd_resp_set_type(req, s_STREAM_CONTENT_TYPE);
if (res != ESP_OK) return res;
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
while (true) {
fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Camera get frame failed");
break;
}
res = httpd_resp_send_chunk(req, s_STREAM_BOUNDARY, strlen(s_STREAM_BOUNDARY));
if (res != ESP_OK) {
Serial.print("Multipart/x-mixed-replace HTTPD not ESP_OK:");
Serial.println(res);
break;
}
size_t hlen = snprintf((char *)part_buf, 64, s_STREAM_PART, fb->len);
res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen);
if (res != ESP_OK) {
Serial.println("Content-Type not ESP_OK");
break;
}
res = httpd_resp_send_chunk(req, (const char *)fb->buf, fb->len);
if (res != ESP_OK) {
Serial.println("HTTPD send image buffer not ESP_OK");
break;
}
esp_camera_fb_return(fb);
fb = NULL;
}
return res;
}