ESP32 CAM crash on fmt2rgb888
Posted: Mon Jul 12, 2021 2:17 am
I can't understand why my ESP32 CAM is crashing when I call fmt2rgb888 in my code. At first, I opened a JPG file from the SD Card then passed it to fmt2rgb888, then I changed it to just get a frame from the camera but it still crashes with the same error. Btw, I use PlatformIO.
I was able to get the stack trace using ESP32 Exception Decoder, but I don't understand the trace. I hope someone can help me. Thank you.
This is my code that crashes on fmt2rgb888. I excluded the other functions because they are working and not relevant to this problem.
This is the serial monitor output
I was able to get the stack trace using ESP32 Exception Decoder, but I don't understand the trace. I hope someone can help me. Thank you.
This is my code that crashes on fmt2rgb888. I excluded the other functions because they are working and not relevant to this problem.
Code: Select all
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
// setup_tft_display();
// start_wifi();
start_camera();
start_sdcard();
enroll_faces_from_sdcard();
// start_web_server(nullptr);
}
void enroll_faces_from_sdcard() {
mtmn_config.type = FAST; // FAST or NORMAL
mtmn_config.min_face = 80;
mtmn_config.pyramid = 0.707;
mtmn_config.pyramid_times = 4;
mtmn_config.p_threshold.score = 0.6;
mtmn_config.p_threshold.nms = 0.7;
mtmn_config.p_threshold.candidate_number = 20;
mtmn_config.r_threshold.score = 0.7;
mtmn_config.r_threshold.nms = 0.7;
mtmn_config.r_threshold.candidate_number = 10;
mtmn_config.o_threshold.score = 0.7;
mtmn_config.o_threshold.nms = 0.7;
mtmn_config.o_threshold.candidate_number = 1;
Serial.println("face_id_init(...)");
face_id_init(&id_list, FACE_ID_SAVE_NUMBER, ENROLL_CONFIRM_TIMES);
dl_matrix3du_t *aligned_face = NULL;
int8_t left_sample_face = NULL;
dl_matrix3du_t *image_matrix = NULL;
Serial.println("Opening faces folder");
fs::File root = SD_MMC.open(FACES_FOLDER);
if (!root) {
Serial.println("Failed to open directory");
ESP.restart();
}
auto fb = esp_camera_fb_get();
Serial.println("Opening first file");
fs::File file = root.openNextFile();
while (file) {
if (!file.isDirectory()) {
Serial.printf("File: %s\n", file.name());
// Load file as char buffer
Serial.println("Reading file as char buffer");
Serial.printf("Size: %d\n", file.size());
uint8_t* buf = (uint8_t*) malloc (file.size());
int i = 0;
while (file.available()) {
buf[i] = file.read();
i++;
}
Serial.println("Creating image matrix");
// Missing null check for image_matrix but assume it works for now
image_matrix = dl_matrix3du_alloc(1, image_width, image_height, 3);
if (!image_matrix) {
Serial.println("Failed to allocate image_matrix");
return;
}
if (!image_matrix->item) {
Serial.println("image_matrix->item is null");
return;
}
// Convert char buffer to RGB888 image, put image data in image_matrix
Serial.println("Convert char buffer to RGB888");
// This line causes a crash whether I use the file JPEG or the frame from the camera
fmt2rgb888(fb->buf, fb->len, fb->format, (uint8_t*)image_matrix->item);
Serial.println("Finding face");
box_array_t *net_boxes = face_detect(image_matrix, &mtmn_config);
if (net_boxes && net_boxes->len > 0) {
aligned_face = dl_matrix3du_alloc(1, FACE_WIDTH, FACE_HEIGHT, 3);
if (align_face(net_boxes, image_matrix, aligned_face) == ESP_OK) {
if (!aligned_face) { Serial.println("Align face failed"); continue; }
int8_t left_sample_face = enroll_face(&id_list, aligned_face);
Serial.printf("Enrolling Face ID: %d, Sample %d\n", id_list.tail, ENROLL_CONFIRM_TIMES - left_sample_face);
if (left_sample_face == 0) enroll_id = id_list.tail;
}
} else {
Serial.printf("No face detected in file: %s\n", file.name());
}
dl_lib_free(net_boxes->score);
dl_lib_free(net_boxes->box);
dl_lib_free(net_boxes->landmark);
dl_lib_free(net_boxes);
net_boxes = NULL;
dl_matrix3du_free(image_matrix);
free(buf);
}
file = root.openNextFile();
}
file.close();
esp_camera_fb_return(fb);
}
Code: Select all
Initializing ESP Camera
Initialized ESP Camera
SD_MMC.begin(/sdcard)
Mounted SD Card (SD_MMC) to /sdcard
face_id_init(...)
Opening faces folder
Opening first file
File: /faces/1.JPG
Reading file as char buffer
Size: 14323
Creating image matrix
Convert char buffer to RGB888
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400dfe0e PS : 0x00060c30 A0 : 0x800d5598 A1 : 0x3ffb1d80
A2 : 0x00000000 A3 : 0x3ffc222c A4 : 0x00000002 A5 : 0x00000000
A6 : 0x00000000 A7 : 0x3ffb0060 A8 : 0x00000a1c A9 : 0x3ffb1e04
A10 : 0x00000001 A11 : 0x00000000 A12 : 0x3ffb8218 A13 : 0x00000000
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000010 LBEG : 0x4008b785 LEND : 0x4008b795 LCOUNT : 0xfffffff8
ELF file SHA256: 0000000000000000
Backtrace: 0x400dfe0e:0x3ffb1d80 0x400d5595:0x3ffb1da0 0x400dfe83:0x3ffb1de0 0x400dad99:0x3ffb1ea0 0x400dae9d:0x3ffb1ed0 0x400d313e:0x3ffb1f10 0x400d32e3:0x3ffb1f80 0x400d7afe:0x3ffb1fb0 0x4008dede:0x3ffb1fd0
#0 0x400dfe0e:0x3ffb1d80 in _jpg_read at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/components/esp32-camera/conversions/esp_jpg_decode.c:75
#1 0x400d5595:0x3ffb1da0 in jd_prepare at .pio\libdeps\esp32cam\TJpg_Decoder\src/tjpgd.c:1783
#2 0x400dfe83:0x3ffb1de0 in esp_jpg_decode at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/components/esp32-camera/conversions/esp_jpg_decode.c:101
#3 0x400dad99:0x3ffb1ea0 in jpg2rgb888 at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/components/esp32-camera/conversions/to_bmp.c:181
#4 0x400dae9d:0x3ffb1ed0 in fmt2rgb888 at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/components/esp32-camera/conversions/to_bmp.c:187
#5 0x400d313e:0x3ffb1f10 in enroll_faces_from_sdcard() at src/main.cpp:184
#6 0x400d32e3:0x3ffb1f80 in setup() at src/main.cpp:184
#7 0x400d7afe:0x3ffb1fb0 in loopTask(void*) at C:\Users\Martin\.platformio\packages\framework-arduinoespressif32\cores\esp32/main.cpp:18
#8 0x4008dede:0x3ffb1fd0 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8