joachimBurket / esp32-opencv

Shrinked OpenCV for ESP32
Other
324 stars 69 forks source link

Error when using with objdetect module #6

Open paleja opened 2 years ago

paleja commented 2 years ago

Hi Joachim, Thank You very much for this clone. I have successfully compiled it including 'objdetect' module, I just needed to add #pragma GCC optimize ("-O0") fix before virtual void knnSearch in flann/lsh_index.h.

I can compile and flash my project to Esp32-cam (Qr codes recognition), but I'm stuck at boot error. I see your comment in imgwarp.cpp, // Modif ESP32: allocate buffers on heap. FIXME: changed access from 2 or 3 dimensions to 1 dimension. Need to find usages of these tables to modify access Can you please point me to right direction? This is the error:

I (29) boot: ESP-IDF v4.3.2-dirty 2nd stage bootloader
I (29) boot: compile time 12:46:02
I (29) boot: chip revision: 1
I (32) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (39) qio_mode: Enabling default flash chip QIO
I (45) boot.esp32: SPI Speed      : 80MHz
I (49) boot.esp32: SPI Mode       : QIO
I (54) boot.esp32: SPI Flash Size : 4MB
I (58) boot: Enabling RNG early entropy source...
I (64) boot: Partition Table:
I (67) boot: ## Label            Usage          Type ST Offset   Length
I (75) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (82) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (89) boot:  2 factory          factory app      00 00 00010000 00200000
I (97) boot: End of partition table
I (101) boot_comm: chip revision: 1, min. application chip revision: 0
I (108) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=58d60h (363872) map
I (225) esp_image: segment 1: paddr=00068d88 vaddr=3ffb0000 size=07290h ( 29328) load
I (234) esp_image: segment 2: paddr=00070020 vaddr=400d0020 size=13b710h (1292048) map
I (617) esp_image: segment 3: paddr=001ab738 vaddr=3ffb7290 size=024e0h (  9440) load
I (621) esp_image: segment 4: paddr=001adc20 vaddr=40080000 size=12e9ch ( 77468) load
I (650) esp_image: segment 5: paddr=001c0ac4 vaddr=50000000 size=00010h (    16) load
I (661) boot: Loaded app from partition at offset 0x10000
I (662) boot: Disabling RNG early entropy source...
I (673) psram: This chip is ESP32-D0WD
I (674) spiram: Found 64MBit SPI RAM device
I (674) spiram: SPI RAM mode: flash 80m sram 80m
I (679) spiram: PSRAM initialized, cache is in low/high (2-core) mode.
I (686) cpu_start: Pro cpu up.
I (690) cpu_start: Starting app cpu, entry point is 0x40081694
0x40081694: call_start_cpu1 at /home/jan/esp/esp-idf/components/esp_system/port/cpu_start.c:150

I (682) cpu_start: App cpu up.
I (1187) spiram: SPI SRAM memory test OK
I (1195) cpu_start: Pro cpu start user code
I (1195) cpu_start: cpu freq: 240000000
I (1195) cpu_start: Application information:
I (1198) cpu_start: Project name:     homebox-esp32-cam
I (1204) cpu_start: App version:      v0.1-4-g4d6d526-dirty
I (1210) cpu_start: Compile time:     Jan 31 2022 12:45:55
I (1216) cpu_start: ELF file SHA256:  ff3496a3ec0450c8...
I (1222) cpu_start: ESP-IDF:          v4.3.2-dirty
I (1228) heap_init: Initializing. RAM available for dynamic allocation:
I (1235) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (1241) heap_init: At 3FFBDBD8 len 00022428 (137 KiB): DRAM
I (1247) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (1254) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (1260) heap_init: At 40092E9C len 0000D164 (52 KiB): IRAM
I (1267) spiram: Adding pool of 4096K of external SPI memory to heap allocator
I (1275) spi_flash: detected chip: generic
I (1279) spi_flash: flash io: qio

abort() was called at PC 0x40104942 on core 0
0x40104942: int abort_return<int>() at /home/jan/esp/esp-idf/components/cxx/cxx_exception_stubs.cpp:28

Backtrace:0x40081b9e:0x3ffe3540 0x4008c885:0x3ffe3560 0x40091cfe:0x3ffe3580 0x40104942:0x3ffe35f0 0x4010496f:0x3ffe3610 0x400f6eb3:0x3ffe3630 0x400e79e6:0x3ffe3650 0x400f701d:0x3ffe3670 0x40147eb2:0x3ffe3690 0x40148e9f:0x3ffe3bd0 0x400d2f87:0x3ffe3bf0 0x400d3199:0x3ffe3c10 0x400818d1:0x3ffe3c50 0x40079579:0x3ffe3c80 |<-CORRUPTED
0x40081b9e: panic_abort at /home/jan/esp/esp-idf/components/esp_system/panic.c:393

0x4008c885: esp_system_abort at /home/jan/esp/esp-idf/components/esp_system/system_api.c:112

0x40091cfe: abort at /home/jan/esp/esp-idf/components/newlib/abort.c:46

0x40104942: int abort_return<int>() at /home/jan/esp/esp-idf/components/cxx/cxx_exception_stubs.cpp:28

0x4010496f: __wrap__Unwind_RaiseException at /home/jan/esp/esp-idf/components/cxx/cxx_exception_stubs.cpp:153

0x400f6eb3: __cxa_throw at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:90

0x400e79e6: operator new(unsigned int) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/new_op.cc:54

0x400f701d: operator new[](unsigned int) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/new_opv.cc:32

0x40147eb2: cv::initInterTab2D(int, bool) at imgwarp.cpp:?

0x40148e9f: _GLOBAL__sub_I_imgwarp_cpp at imgwarp.cpp:?

0x400d2f87: do_global_ctors at /home/jan/esp/esp-idf/components/esp_system/startup.c:193 (discriminator 3)

0x400d3199: start_cpu0_default at /home/jan/esp/esp-idf/components/esp_system/startup.c:411

0x400818d1: call_start_cpu0 at /home/jan/esp/esp-idf/components/esp_system/port/cpu_start.c:536
joachimBurket commented 2 years ago

Hi Paleja, Sorry for the delay, I'm currently working on other projects. Glad this project can help! :)

Did you had any chance on this error?

joachimBurket commented 2 years ago

The problem I had in the imgwarp.cpp file was that some tables (NNDeltaTab, BilinearTab, BicubicTab and Lanczos4Tab) were statically allocated and taking too much space on the DRAM (see this section. The fix I found for it was to initialize them on the heap instead (see this commit). I think the opencv features I was using at the time weren't using those arrays, so this fix wasn't tested.

0x400f701d: operator new[](unsigned int) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/new_opv.cc:32 0x40147eb2: cv::initInterTab2D(int, bool) at imgwarp.cpp:?

From the backtrace you sent, it seems that the error is in the new operator, so most likely in the allocateTables() method

paleja commented 2 years ago

Thank You for response. In the meantime I finished my project with esp-who library, but I hope I will come back to this soon.