Building OpenCV for the ESP32 error

williamb
Posts: 2
Joined: Fri Jan 05, 2024 10:40 am

Building OpenCV for the ESP32 error

Postby williamb » Fri Jan 05, 2024 11:01 am

I want to use OpenCV locally on the ESP and the IDF Component Registry has a OpenCV component. I can create projects from the examples, however I can't build them. I get this error:

Code: Select all

CMake Error at C:/Users/williamb/.espressif/tools/cmake/3.24.0/share/cmake-3.24/Modules/ExternalProject.cmake:2471:EVAL:2 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_PROPERTY:idf::opencv,INCLUDE_DIRECTORIES>

  Target "idf::opencv" not found.
Call Stack (most recent call first):
  C:/Users/williamb/.espressif/tools/cmake/3.24.0/share/cmake-3.24/Modules/ExternalProject.cmake:2471 (cmake_language)
  C:/Users/williamb/.espressif/tools/cmake/3.24.0/share/cmake-3.24/Modules/ExternalProject.cmake:3699:EVAL:2 (ExternalProject_Add_Step)
  C:/Users/williamb/.espressif/tools/cmake/3.24.0/share/cmake-3.24/Modules/ExternalProject.cmake:3699 (cmake_language)
  C:/Users/williamb/.espressif/tools/cmake/3.24.0/share/cmake-3.24/Modules/ExternalProject.cmake:4170 (_ep_add_configure_command)
  managed_components/espressif__opencv/CMakeLists.txt:109 (ExternalProject_Add)


I ran "idf.py add-dependency "espressif/opencv^4.7.0~3" in the project and that brought the OpenCV managed components in. But it still doesn't work. The install button on the Registry page also doesn't seem to do anything. Any suggestions?

(If it helps the only feature I really want from OpenCV is simpleBlobDetection, Resize, bilateralFilter, Filter2D and fastNlMeansDenoising).

nopnop2002
Posts: 112
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: Building OpenCV for the ESP32 error

Postby nopnop2002 » Mon Jan 15, 2024 1:12 am


**txf**
Posts: 12
Joined: Thu Apr 21, 2022 3:03 pm

Re: Building OpenCV for the ESP32 error

Postby **txf** » Mon Jan 15, 2024 11:59 am

In case you aren't specifically tied to use the openCV in the component registry there is this https://github.com/joachimBurket/esp32-opencv project, which I have used and I know it works.

williamb
Posts: 2
Joined: Fri Jan 05, 2024 10:40 am

Re: Building OpenCV for the ESP32 error

Postby williamb » Mon Jan 15, 2024 3:35 pm

Thanks, it's good to see it's being developed.

I've seen this repo and some projects based on it but I run into the same issues.

I'm a little confused on that part as I get the same error for both however obviously people have got the joachimBurket version working.

**txf**
Posts: 12
Joined: Thu Apr 21, 2022 3:03 pm

Re: Building OpenCV for the ESP32 error

Postby **txf** » Tue Jan 16, 2024 12:58 pm

Have you tried compiling the example application, maybe you could check and see what the CMakeLists.txt is like for the example?

It's been a while for me, but another thing to bear in mind that if you're compiling your own openCV binaries, you might have issues in windows, you might have to do it under WSL or linux.

nopnop2002
Posts: 112
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: Building OpenCV for the ESP32 error

Postby nopnop2002 » Sat Jan 20, 2024 3:00 am

It appears that the https://github.com/joachimBurket/esp32-opencv project depends on a specific version of ESP-IDF.

I cross-compiled with ESP-IDF v5.1.2 on Linux, but a lot of errors occurred.

---

https://github.com/joachimBurket/esp32-opencv
This repository requires ESP32 with PARAM and ESP-IDF V4.4.x.
I used an ESP32S3 with PSRAM.

Code: Select all

$ idf.py --version
ESP-IDF v4.4.5-104-g8b94183c9c-dirty

$ cd $HOME

$ find . -name toolchain-esp32s3.cmake -print
./esp-idf/tools/cmake/toolchain-esp32s3.cmake

$ git clone https://github.com/joachimBurket/esp32-opencv

$ cd esp32-opencv/esp32/scripts

$ ./build_opencv_for_esp32.sh $HOME/esp-idf/tools/cmake/toolchain-esp32s3.cmake

$ ls -l ../lib/opencv
合計 17892
drwxr-xr-x 1 nop nop      40  1月 20 12:40 3rdparty
-rw-r--r-- 1 nop nop  859226  1月 20 12:40 libade.a
-rw-r--r-- 1 nop nop 8682766  1月 20 12:40 libopencv_core.a
-rw-r--r-- 1 nop nop  500044  1月 20 12:40 libopencv_imgcodecs.a
-rw-r--r-- 1 nop nop 8270242  1月 20 12:40 libopencv_imgproc.a
drwxr-xr-x 1 nop nop     180  1月 20 12:40 opencv2

$ cd ../lib

$ cp -r opencv ../examples/hello_opencv/main/


$ cd ../examples/hello_opencv

$ idf.py set-target esp32s3

$ idf.py menuconfig
Change Flash size to 4M.
Add Parition Table

$ idf.py flash monitor

I (490) hello_opencv: Starting main
M1 =
 [  0,   0, 255,   0,   0, 255;
   0,   0, 255,   0,   0, 255]

M2 =
 [  0,   0, 111,   0,   0, 111;
   0,   0, 111,   0,   0, 111]

eye =
 [0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0;
 0, 0.1, 0, 0, 0, 0, 0, 0, 0, 0;
 0, 0, 0.1, 0, 0, 0, 0, 0, 0, 0;
 0, 0, 0, 0.1, 0, 0, 0, 0, 0, 0;
 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0;
 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0;
 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0;
 0, 0, 0, 0, 0, 0, 0, 0.1, 0, 0;
 0, 0, 0, 0, 0, 0, 0, 0, 0.1, 0;
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.1]

ones =
 [  3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3;
   3,   3,   3,   3]

floats vector =
 [3.1415927;
 2;
 3.01]

Gray matrix =
 [  1,   2,   3,   4,   5;
   6,   7,   8,   9,  10;
  11,  12,  13,  14,  15]

Thresholded matrix =
 [  0,   0,   0,   0,   0;
   0,   0, 255, 255, 255;
 255, 255, 255, 255, 255]

Resized matrix =
 [  2,   3,   4,   6;
   9,  10,  11,  13]

nicklasb
Posts: 10
Joined: Sun Apr 24, 2022 9:11 pm

Re: Building OpenCV for the ESP32 error

Postby nicklasb » Sun Aug 11, 2024 1:19 pm

If it helps, I made a PR to joachimBurket/esp32-opencv to make it work on the ESP32-CAM, and fixed IDF 5.3.0 support:
https://github.com/joachimBurket/esp32-opencv/pull/23

abbas1375
Posts: 1
Joined: Mon Nov 25, 2024 1:08 pm

Re: Building OpenCV for the ESP32 error

Postby abbas1375 » Mon Nov 25, 2024 1:29 pm

hello everyone, i have problem to work with standalone opencv library for esp32 while I'm using hello_opencv example, this is my error:
  1.  *  Executing task: C:\Espressif\tools\ninja\1.11.1\ninja.exe  
  2.  
  3. [1/4] cmd.exe /C "cd /D C:\Users\kia120\Desktop\espidf\hello_world\build\esp-idf\esptool_py && C:\Espressif\py...ld/build/partition_table/partition-table.bin C:/Users/kia120/Desktop/espidf/hello_world/build/hello_world.bin
  4. FAILED: esp-idf/esptool_py/CMakeFiles/app_check_size C:/Users/kia120/Desktop/espidf/hello_world/build/esp-idf/esptool_py/CMakeFiles/app_check_size
  5. cmd.exe /C "cd /D C:\Users\kia120\Desktop\espidf\hello_world\build\esp-idf\esptool_py && C:\Espressif\python_env\idf5.3_py3.11_env\Scripts\python.exe C:/Espressif/frameworks/esp-idf-v5.3.1/components/partition_table/check_sizes.py --offset 0x8000 partition --type app C:/Users/kia120/Desktop/espidf/hello_world/build/partition_table/partition-table.bin C:/Users/kia120/Desktop/espidf/hello_world/build/hello_world.bin"
  6. Error: app partition is too small for binary hello_world.bin size 0x10b5d0:
  7.  - Part 'factory' 0/0 @ 0x10000 size 0x100000 (overflow 0xb5d0)
  8. [2/4] Performing build step for 'bootloader'
  9. [1/1] cmd.exe /C "cd /D C:\Users\kia120\Desktop\espidf\hello_world\build\bootloader\esp-idf\esptool_py && C:\Espressif\python_env\idf5.3_py3.11_env\Scripts\python.exe C:/Espressif/frameworks/esp-idf-v5.3.1/components/partition_table/check_sizes.py --offset 0x8000 bootloader 0x1000 C:/Users/kia120/Desktop/espidf/hello_world/build/bootloader/bootloader.bin"
  10. Bootloader binary size 0x6880 bytes. 0x780 bytes (7%) free.
  11. ninja: build stopped: subcommand failed.
  12.  
  13. *  The terminal process "C:\Espressif\tools\ninja\1.11.1\ninja.exe" terminated with exit code: 1.
i changed the partitions.csv file and its not work!
I would be grateful if you could help me.

nopnop2002
Posts: 112
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: Building OpenCV for the ESP32 error

Postby nopnop2002 » Tue Nov 26, 2024 4:18 am

Check these.

- sdkconfig.defaults


# Partition Table
#
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"

#
# Serial flasher config
#
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y

#
# Compiler options
#
CONFIG_COMPILER_CXX_EXCEPTIONS=y
CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE=0
CONFIG_CXX_EXCEPTIONS=y
CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE=0

#
# Memory protection
#
CONFIG_ESP_MAIN_TASK_STACK_SIZE=20480
CONFIG_ESP_TASK_WDT_EN=n

- partitions.csv

# Espressif ESP32 Partition Table
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 3M,
storage, data, spiffs, , 1500k,

Who is online

Users browsing this forum: Bing [Bot], Jorgen, snutw_ and 106 guests