opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

Error generating Matlab code - ModuleNotFoundError: No module named 'hdr_parser'

Open Qubiz opened this issue 3 years ago • 1 comments

System information (version)
  • OpenCV => 4.6.0-dev
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2022 - MSVC 19.32.31332.0
Detailed description

I am trying to compile OpenCV with Matlab support. Everything seems to work fine, except that it says that 'bindings will not be generated'.

During the CMake configuration step there is the following error:

-- Trying to generate Matlab code
Traceback (most recent call last):
  File "H:\Projects\opencv-playground\ext\opencv\opencv-contrib\modules\matlab\generator\gen_matlab.py", line 194, in <module>
    mwg.gen(args.moduleroot, args.modules, args.extra, args.outdir)
  File "H:\Projects\opencv-playground\ext\opencv\opencv-contrib\modules\matlab\generator\gen_matlab.py", line 51, in gen
    import hdr_parser
ModuleNotFoundError: No module named 'hdr_parser'

-- Error generating Matlab code. Disabling Matlab bindings...

I try to build with the following CMake variables set:

BUILD_TESTS="OFF"
CUDA_ARCH_BIN="7.5"
WITH_CUDA="ON"
WITH_CUDEV="ON"
WITH_MATLAB="ON"

Complete final configuration:

-- 
-- General configuration for OpenCV 4.6.0-dev =====================================
--   Version control:               4.6.0-69-g47f30a04d2-dirty
-- 
--   Extra modules:
--     Location (extra):            H:/Projects/opencv-playground/ext/opencv/opencv-contrib/modules
--     Version control (extra):     4.6.0-16-g9d0a451b
-- 
--   Platform:
--     Timestamp:                   2022-07-27T06:42:42Z
--     Host:                        Windows 10.0.22000 AMD64
--     CMake:                       3.22.3
--     CMake generator:             Ninja
--     CMake build tool:            C:/ProgramData/chocolatey/bin/ninja.exe
--     MSVC:                        1932
--     Configuration:               Release
-- 
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (16 files):         + SSSE3 SSE4_1
--       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (32 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (5 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe  (ver 19.32.31332.0)
--     C++ flags (Release):         /MD  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589  /O2 /Ob2 /DNDEBUG 
--     C++ flags (Debug):           /MD  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589  /Zi /Ob0 /Od /RTC1 
--     C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe
--     C flags (Release):           /DWIN32 /D_WINDOWS  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS       /O2 /Ob2 /DNDEBUG 
--     C flags (Debug):             /DWIN32 /D_WINDOWS  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS     /Zi /Ob0 /Od /RTC1 
--     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO 
--     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL 
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cufft.lib -LIBPATH:"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib/x64"
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor matlab mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 alphamat cvv freetype hdf java julia matlab ovis python2 sfm viz
--     Applications:                perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   Windows RT support:            NO
-- 
--   GUI:                           WIN32UI
--     Win32 UI:                    YES
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        build (ver 1.2.12)
--     JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.2.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES (prebuilt binaries)
--       avcodec:                   YES (58.134.100)
--       avformat:                  YES (58.76.100)
--       avutil:                    YES (56.70.100)
--       swscale:                   YES (5.9.100)
--       avresample:                YES (4.0.0)
--     GStreamer:                   NO
--     DirectShow:                  YES
--     Media Foundation:            YES
--       DXVA:                      YES
-- 
--   Parallel framework:            Concurrency
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Intel IPP:                   2020.0.0 Gold [2020.0.0]
--            at:                   H:/Projects/opencv-playground/out/build/windows-msvc-release/ext/opencv/opencv/3rdparty/ippicv/ippicv_win/icv
--     Intel IPP IW:                sources (2020.0.0)
--               at:                H:/Projects/opencv-playground/out/build/windows-msvc-release/ext/opencv/opencv/3rdparty/ippicv/ippicv_win/iw
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
-- 
--   NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS)
--     NVIDIA GPU arch:             75
--     NVIDIA PTX archs:
-- 
--   cuDNN:                         NO
-- 
--   OpenCL:                        YES (NVD3D11)
--     Include path:                H:/Projects/opencv-playground/ext/opencv/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python 3:
--     Interpreter:                 C:/Python310/python3.exe (ver 3.10)
--     Libraries:                   C:/Python310/libs/python310.lib (ver 3.10.0)
--     numpy:                       C:/Python310/lib/site-packages/numpy/core/include (ver 1.23.1)
--     install path:                C:/Python310/Lib/site-packages/cv2/python-3.10
-- 
--   Python (for build):            C:/Python310/python3.exe
-- 
--   Java:                          
--     ant:                         NO
--     JNI:                         C:/Program Files/Java/jdk-15/include C:/Program Files/Java/jdk-15/include/win32 C:/Program Files/Java/jdk-15/include
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Matlab:                        YES
--     mex:                         C:/Program Files/MATLAB/R2022a/bin/mex.bat
--     Compiler/generator:          Not working (bindings will not be generated)
-- 
--   Install to:                    H:/Projects/opencv-playground/out/install/windows-msvc-release
-- -----------------------------------------------------------------
Steps to reproduce

As described above.

Qubiz avatar Jul 27 '22 08:07 Qubiz

After some further investigation I have found the cause of the issue.

In the CMakeLists.txt of the Matlab module the path to directory containing hdr_parser.py is set as follows: set(HDR_PARSER_PATH ${CMAKE_SOURCE_DIR}/modules/python/src2)

CMAKE_SOURCE_DIR always points to top level of the current CMake source tree.

Our project is structed like this, so hdr_parser.py cannot be found:

Project root (CMAKE_SOURCE_DIR)
  ext
    opencv
      opencv
      opencv_contrib
  CMakeLists.txt

The solution was to change modules/matlab/CMakeLists.txt and set the path using the OpenCV_SOURCE_DIR var like this: set(HDR_PARSER_PATH ${OpenCV_SOURCE_DIR}/modules/python/src2).

This seems to be a more robust way of finding the OpenCV directory and it allows for a more flexible project structure.

Qubiz avatar Jul 28 '22 07:07 Qubiz

Were you able to successfully build the Matlab bindings using VS 2022 and Matlab 2022a? Even with your fix I still get the same error.

TheKinigit avatar Aug 24 '22 17:08 TheKinigit