joachimBurket / esp32-opencv

Shrinked OpenCV for ESP32
Other
361 stars 76 forks source link

esp32-opencv build failed with error: 'recursive_mutex' in namespace 'std' does not name a type #14

Open kowshik1234 opened 1 year ago

kowshik1234 commented 1 year ago

@joachimBurket I have followed everything as stated in this wikipage here. The configuring and the generation part is fine. When I tried compiling, after making the alloc.cpp fix as stated in the documentation when I proceeded with the build I got the following errors regarding the std::mutex and thread related.

Attaching entire build log.

[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/adler32.c.obj
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/compress.c.obj
[  2%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/crc32.c.obj
[  2%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/deflate.c.obj
[  2%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzclose.c.obj
[  3%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzlib.c.obj
[  3%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzread.c.obj
[  4%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzwrite.c.obj
[  4%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/inflate.c.obj
[  5%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/infback.c.obj
[  5%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/inftrees.c.obj
[  6%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/inffast.c.obj
[  6%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/trees.c.obj
[  7%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/uncompr.c.obj
[  7%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/zutil.c.obj
[  8%] Linking C static library ../lib/libzlib.a
[  8%] Built target zlib
[  8%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/png.c.obj
[  9%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngerror.c.obj
[  9%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngget.c.obj
[ 10%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngmem.c.obj
[ 10%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngpread.c.obj
[ 11%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngread.c.obj
[ 11%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngrio.c.obj
[ 11%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngrtran.c.obj
[ 12%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngrutil.c.obj
[ 12%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngset.c.obj
[ 13%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngtrans.c.obj
[ 13%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngwio.c.obj
[ 14%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngwrite.c.obj
[ 14%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngwtran.c.obj
[ 15%] Building C object 3rdparty/libpng/CMakeFiles/libpng.dir/pngwutil.c.obj
[ 15%] Linking C static library ../lib/liblibpng.a
[ 15%] Built target libpng
[ 15%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/alloc.cpp.obj
[ 15%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/assert.cpp.obj
[ 16%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/check_cycles.cpp.obj
[ 16%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/edge.cpp.obj
[ 17%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/execution_engine.cpp.obj
[ 17%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/graph.cpp.obj
[ 18%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/memory_accessor.cpp.obj
[ 18%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/memory_descriptor.cpp.obj
[ 19%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/memory_descriptor_ref.cpp.obj
[ 19%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/memory_descriptor_view.cpp.obj
[ 20%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/metadata.cpp.obj
[ 20%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/metatypes.cpp.obj
[ 20%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/node.cpp.obj
[ 21%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/passes/communications.cpp.obj
[ 21%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/search.cpp.obj
[ 22%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/subgraphs.cpp.obj
[ 22%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/topological_sort.cpp.obj
[ 23%] Linking CXX static library ../lib/libade.a
[ 23%] Built target ade
[ 23%] Built target opencv_videoio_plugins
[ 24%] Processing OpenCL kernels (core)
-- /home/kowshik/Downloads/esp32-opencv-master/build/modules/core/opencl_kernels_core.hpp contains the same content
[ 24%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/algorithm.cpp.obj
In file included from /home/kowshik/Downloads/esp32-opencv-master/modules/core/src/precomp.hpp:49:0,
                 from /home/kowshik/Downloads/esp32-opencv-master/modules/core/src/algorithm.cpp:43:
/home/kowshik/Downloads/esp32-opencv-master/modules/core/include/opencv2/core/utility.hpp:714:14: error: 'recursive_mutex' in namespace 'std' does not name a type
 typedef std::recursive_mutex Mutex;
              ^
/home/kowshik/Downloads/esp32-opencv-master/modules/core/include/opencv2/core/utility.hpp:715:25: error: 'Mutex' is not a member of 'cv'
 typedef std::lock_guard<cv::Mutex> AutoLock;
                         ^
/home/kowshik/Downloads/esp32-opencv-master/modules/core/include/opencv2/core/utility.hpp:715:25: error: 'Mutex' is not a member of 'cv'
/home/kowshik/Downloads/esp32-opencv-master/modules/core/include/opencv2/core/utility.hpp:715:34: error: template argument 1 is invalid
 typedef std::lock_guard<cv::Mutex> AutoLock;
                                  ^
In file included from /home/kowshik/Downloads/esp32-opencv-master/modules/core/src/algorithm.cpp:43:0:
/home/kowshik/Downloads/esp32-opencv-master/modules/core/src/precomp.hpp:365:5: error: 'Mutex' in namespace 'cv' does not name a type
 cv::Mutex& getInitializationMutex();
     ^
cc1plus: warning: unrecognized command line option '-Wno-unnamed-type-template-args'
cc1plus: warning: unrecognized command line option '-Wno-frame-address'
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/build.make:103: modules/core/CMakeFiles/opencv_core.dir/src/algorithm.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:845: modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

Please let me know how to fix this? What causes this and I have seen similar error when I tried to build opencv standalone with arm-none-eabi-gcc compiler.

Thanks, G Kowshik

nopnop2002 commented 10 months ago

Requires ESP32 with PARAM and ESP-IDF V4.4.x. This is a record of when I built a library for ESP32S3.

$ 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]
sergem155 commented 9 months ago

Thank you @nopnop2002 your excellent example saved a ton of time for me! There should be "idf.py build" before the last comment to make your guide perfect.