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: 109
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: 11
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: 11
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: 109
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

Who is online

Users browsing this forum: Baidu [Spider], MicroController and 198 guests