Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error when including MATLAB module #3886

Open
CodeHotel opened this issue Feb 18, 2025 · 0 comments
Open

Build error when including MATLAB module #3886

CodeHotel opened this issue Feb 18, 2025 · 0 comments

Comments

@CodeHotel
Copy link

CodeHotel commented Feb 18, 2025

Warning: this may be duplicate with Issue #3781. However, since #3781 has not been addressed by anyone and little info was provided on that post, I repost the issue in hopes that it would be addressed.

  1. Problem: When compiling with -DWITH_MATLAB=ON, following error happens
[ 87%] Built target opencv_perf_superres
[ 88%] Building CXX object modules/videostab/CMakeFiles/example_videostab_videostab.dir/samples/videostab.cpp.o
[ 88%] Building CXX object modules/videostab/CMakeFiles/opencv_test_videostab.dir/test/test_main.cpp.o
[ 88%] Built target example_gpu_morphology
[ 88%] Compiling Matlab source files. This could take a while...
Matlab: compiling 333 files
[1/333] Compiling: CamShift
[ 88%] Built target example_gpu_hog
[ 88%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
[ 88%] Built target example_gpu_surf_keypoint_matcher
[ 88%] Building CXX object modules/videostab/CMakeFiles/opencv_test_videostab.dir/test/test_motion_estimation.cpp.o
[ 88%] Linking CXX executable ../../bin/example_gpu_generalized_hough
[ 88%] Built target example_gpu_generalized_hough
[ 88%] Building CXX object samples/cpp/CMakeFiles/example_tutorial_pnp_registration.dir/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp.o
[ 88%] Linking CXX executable ../../bin/example_gpu_stereo_match
[ 88%] Built target example_gpu_stereo_match
[ 88%] Building CXX object samples/cpp/CMakeFiles/example_cpp_watershed.dir/watershed.cpp.o
[ 88%] Building CXX object modules/videostab/CMakeFiles/opencv_test_videostab.dir/test/test_stabilizer.cpp.o
CMake Error at /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/compile.cmake:54 (message):
  Failed to compile CamShift: In file included from
  /home/codehotel/rhel_init/cv_cuda/release_general/modules/matlab/src/CamShift.cpp:13:



  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:88:17:
  error: âDualTVL1OpticalFlowâ was not declared in this scope; did
  you mean âreadOpticalFlowâ?

     88 | typedef cv::Ptr<DualTVL1OpticalFlow> Ptr_DualTVL1OpticalFlow;
        |                 ^~~~~~~~~~~~~~~~~~~
        |                 readOpticalFlow


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:88:36:
  error: template argument 1 is invalid

     88 | typedef cv::Ptr<DualTVL1OpticalFlow> Ptr_DualTVL1OpticalFlow;
        |                                    ^


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:95:17:
  error: âTonemapDurandâ was not declared in this scope; did you
  mean âTonemapDragoâ?

     95 | typedef cv::Ptr<TonemapDurand> Ptr_TonemapDurand;
        |                 ^~~~~~~~~~~~~
        |                 TonemapDrago


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:95:30:
  error: template argument 1 is invalid

     95 | typedef cv::Ptr<TonemapDurand> Ptr_TonemapDurand;
        |                              ^


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:477:11:
  error: âcv::bridge::Bridge& cv::bridge::Bridge::operator=(const
  Ptr_DualTVL1OpticalFlow&)â cannot be overloaded with
  âcv::bridge::Bridge& cv::bridge::Bridge::operator=(const int&)â

    477 |   Bridge& operator=(const Ptr_DualTVL1OpticalFlow& ) { return *this; }
        |           ^~~~~~~~


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:292:11:
  note: previous declaration âcv::bridge::Bridge&
  cv::bridge::Bridge::operator=(const int&)â

    292 |   Bridge& operator=(const int& ) { return *this; }
        |           ^~~~~~~~


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:479:3:
  error: âcv::bridge::Bridge::operator
  cv::bridge::Ptr_DualTVL1OpticalFlow()â cannot be overloaded with
  âcv::bridge::Bridge::operator int()â

    479 |   operator Ptr_DualTVL1OpticalFlow() { return toPtrDualTVL1OpticalFlow(); }
        |   ^~~~~~~~


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:294:3:
  note: previous declaration âcv::bridge::Bridge::operator int()â

    294 |   operator int() { return toInt(); }
        |   ^~~~~~~~


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:512:11:
  error: âcv::bridge::Bridge& cv::bridge::Bridge::operator=(const
  Ptr_TonemapDurand&)â cannot be overloaded with
  âcv::bridge::Bridge& cv::bridge::Bridge::operator=(const int&)â

    512 |   Bridge& operator=(const Ptr_TonemapDurand& ) { return *this; }
        |           ^~~~~~~~


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:292:11:
  note: previous declaration âcv::bridge::Bridge&
  cv::bridge::Bridge::operator=(const int&)â

    292 |   Bridge& operator=(const int& ) { return *this; }
        |           ^~~~~~~~


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:514:3:
  error: âcv::bridge::Bridge::operator
  cv::bridge::Ptr_TonemapDurand()â cannot be overloaded with
  âcv::bridge::Bridge::operator int()â

    514 |   operator Ptr_TonemapDurand() { return toPtrTonemapDurand(); }
        |   ^~~~~~~~


  /home/codehotel/rhel_init/cv_cuda/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:294:3:
  note: previous declaration âcv::bridge::Bridge::operator int()â

    294 |   operator int() { return toInt(); }
        |   ^~~~~~~~





make[2]: *** [modules/matlab/CMakeFiles/opencv_matlab.dir/build.make:73: modules/matlab/compile.proxy] Error 1
make[1]: *** [CMakeFiles/Makefile2:21438: modules/matlab/CMakeFiles/opencv_matlab.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
  1. Environment
    OS: RHEL 9.1 x86_64
    GCC: gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2)
    cmake: 3.20.2
    nvcc: 12.4, V12.4.131
    CuDNN: 8.9.7.29-1
    MATLAB: R2024b Update 4 (24.2.0.2833386) 64-bit (glnxa64)
    OpenCV repository: Release 4.11.0 (0e5254e)

  2. Build Settings
    Cmake prefixes and flags are set up using following commands

#!/bin/bash

set -x

# Release : Python, Cpp Release
cd cv_cuda
[ -d "release_general" ] && sudo rm -rf release_general
mkdir release_general
cd release_general
export CXXFLAGS="-O3 -march=native -mtune=native -fno-lto"
export CFLAGS="-O3 -march=native -mtune=native -fno-lto"
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -DBUILD_opencv_world=OFF \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
      -D BUILD_JAVA=ON \
      -D WITH_LAPACK=ON \
      -D WITH_TBB=ON \
      -D WITH_IPP=ON \
      -D WITH_CUDA=ON \
      -D CUDA_ARCH_BIN="8.9" \
      -D WITH_CUDNN=ON \
      -D OPENCV_DNN_CUDA=ON \
      -D CUDA_FAST_MATH=ON \
      -D ENABLE_FAST_MATH=ON \
      -D WITH_CUBLAS=ON \
      -D WITH_CUFFT=ON \
      -D WITH_OPENGL=ON \
      -D WITH_V4L=ON \
      -D WITH_FFMPEG=ON \
      -D WITH_XINE=ON \
      -D BUILD_DOCS=ON \
      -D BUILD_EXAMPLES=ON \
      -D BUILD_TESTS=ON \
      -D BUILD_PERF_TESTS=ON \
      -D BUILD_NEW_PYTHON_SUPPORT=ON \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D OPENCV_GENERATE_PKGCONFIG=ON \
      -D WITH_QT=ON \
      -D WITH_GTK=ON \
      -D OPENCV_ENABLE_NONFREE=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
      -D WITH_IMGCODEC_GIF=ON \
      -D BUILD_WITH_DEBUG_INFO=OFF \
      -D BUILD_opencv_python3=ON \
      ../opencv
cd ../..

Note, OpenCV and its contrib modules compile without errors when MATLAB module is disabled.

Conversely, I have tested with as much modules disabled to isolate the issue (shown below), but it also fails

#!/bin/bash

set -x

# Release : Python, Cpp Release
cd cv_cuda
[ -d "test" ] && sudo rm -rf test
mkdir test
cd test
export CXXFLAGS="-O3 -march=native -mtune=native -fno-lto"
export CFLAGS="-O3 -march=native -mtune=native -fno-lto"
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -DBUILD_opencv_world=OFF \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D BUILD_JAVA=OFF \
      -D WITH_LAPACK=OFF \
      -D WITH_TBB=OFF \
      -D WITH_IPP=OFF \
      -D WITH_CUDA=OFF \
      -D WITH_OPENGL=OFF \
      -D WITH_V4L=OFF \
      -D WITH_FFMPEG=OFF \
      -D WITH_XINE=OFF \
      -D BUILD_DOCS=OFF \
      -D BUILD_EXAMPLES=OFF \
      -D BUILD_TESTS=OFF \
      -D BUILD_PERF_TESTS=OFF \
      -D BUILD_NEW_PYTHON_SUPPORT=OFF \
      -D INSTALL_C_EXAMPLES=OFF \
      -D INSTALL_PYTHON_EXAMPLES=OFF \
      -D OPENCV_GENERATE_PKGCONFIG=OFF \
      -D WITH_QT=OFF \
      -D WITH_GTK=OFF \
      -D WITH_GTK_2_X=OFF \
      -D OPENCV_ENABLE_NONFREE=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
      -D WITH_IMGCODEC_GIF=OFF \
      -D BUILD_WITH_DEBUG_INFO=OFF \
      -D BUILD_opencv_python3=OFF \
      -D MATLAB_ROOT=/usr/local/MATLAB/R2024b \
      -D WITH_MATLAB=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
      ../opencv
cd ../..
  1. What I have tried
    to opencv_contrib/modules/matlab/CMakeLists.txt, add opencv_optflow
ocv_add_module(matlab   BINDINGS
                        OPTIONAL opencv_core
                                 opencv_imgproc opencv_ml
                                 opencv_imgcodecs opencv_videoio opencv_highgui
                                 opencv_objdetect opencv_flann opencv_features2d
                                 opencv_photo opencv_video opencv_videostab
                                 opencv_calib opencv_calib3d
                                 opencv_stitching opencv_superres
                                 opencv_xfeatures2d
                                 opencv_xphoto
                                 opencv_optflow
)

Then in bridge.hpp, fix
typedef cv::Ptr<DualTVL1OpticalFlow> Ptr_DualTVL1OpticalFlow; to
typedef cv::Ptr<cv::optflow::DualTVL1OpticalFlow> Ptr_DualTVL1OpticalFlow;

This did not resolve the issue. There are multiple other errors regarding operator =, and some seem to originate from cpp files generated during build by modules/matlab/generator/gen_matlab.py
I have failed to fix the errors that were generated one after another when trying to mod the matlab module code and its generator scripts myself.

Is the matlab module of opencv_contrib deprecated or currently unsupported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant