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

OpenCV Matlab Code Generator module make error #3781

Closed
jeremvv opened this issue Aug 19, 2024 · 3 comments
Closed

OpenCV Matlab Code Generator module make error #3781

jeremvv opened this issue Aug 19, 2024 · 3 comments

Comments

@jeremvv
Copy link

jeremvv commented Aug 19, 2024

System information (version)
  • OpenCV => 4.10.0
  • Operating System / Platform => Ubuntu 22.04
  • Compiler => g++ 11.4.0
Detailed description

Hi all,
I'm trying to compile the last OpenCV with the OpenCV Matlab Code Generator module enable in order to call OpenCV methods in Matlab. I was previously using https://github.com/kyamagu/mexopencv when on OpenCV 3. After a new install on my machine and a try with OpenCV 4, I can't make it work.

After successfully running cmake, running make leads to the following errors:

 CMake Error at /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/compile.cmake:65 (message):
  Failed to compile CamShift: In file included from
  /home/jeremy/work/opencv_build/opencv/modules/core/include/opencv2/core.hpp:3415,


                   from /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:52,
                   from /home/jeremy/work/opencv_build/opencv/build/modules/matlab/src/CamShift.cpp:13:

  
  /home/jeremy/work/opencv_build/opencv/modules/core/include/opencv2/core/operations.hpp:58:118:
  warning: â is an unrecognized format function type
  [-Wformat=]

     58 | #    define CV_FORMAT_PRINTF(string_idx, first_to_check) __attribute__ ((format (printf, string_idx, first_to_check)))
        |                                                                                                                      ^

  
  /home/jeremy/work/opencv_build/opencv/modules/core/include/opencv2/core/operations.hpp:499:48:
  note: in expansion of macro â

    499 | CV_EXPORTS String format(const char* fmt, ...) CV_FORMAT_PRINTF(1, 2);
        |                                                ^~~~~~~~~~~~~~~~

  In file included from
  /home/jeremy/work/opencv_build/opencv/build/modules/matlab/src/CamShift.cpp:13:


  
  /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:88:17:
  error: â was not declared in this scope; did
  you mean â?

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

  
  /home/jeremy/work/opencv_build/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/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:95:17:
  error: â was not declared in this scope; did you
  mean â?

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

  
  /home/jeremy/work/opencv_build/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/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:477:11:
  error: â cannot be overloaded with
  â

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

  
  /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:292:11:
  note: previous declaration â

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

  
  /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:479:3:
  error: â cannot be overloaded with
  â

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

  
  /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:294:3:
  note: previous declaration â

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

  
  /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:512:11:
  error: â cannot be overloaded with
  â

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

  
  /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:292:11:
  note: previous declaration â

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

  
  /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:514:3:
  error: â cannot be overloaded with
  â

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

  
  /home/jeremy/work/opencv_build/opencv_contrib/modules/matlab/include/opencv2/matlab/bridge.hpp:294:3:
  note: previous declaration â

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

Could anyone assist me or help me on this ?

@CodeHotel
Copy link
Contributor

CodeHotel commented Feb 26, 2025

Hello, nearly half a year has passed since you have submitted this issue. Are you still in need of the opencv_matlab module?
I am currently working on a fix, and am nearly complete. I will fork, submit, and PR within this week.

I am not a cv contributor, nor have ever contributed to any sizeable open source project.
However, from my debug attempts, what I can currently tell you is

  1. cv::matlab module used to work in 4.0.0-alpha (and beta) but abandoned since then. around 2017-2018, so for opencv 4, matlab module has been alive for few months and dead for nearly 7 years, yet no one has marked it as deprecated or obsolete.
  2. In 4.0.0-rc, changes were made to move optflow from main opencv to to cv_contrib, and matlab, having been abandoned, never took this into account. Similar changes have occured with xphoto
  3. Even after fixing such issue, errors occur at the last stage of build, where mex compilation of bindings occur. I have also found a way around them as well, but the last error involves a pretty unclean fix (inserting using std::string at top of bridge.hpp, but it does its job)
  4. Changes to bridge.hpp and CMakeLists.txt (of matlab module) has fixed the issue for now. I will fork and file a PR report within a few days

I am very glad to know that I was not the only one seeking to fix this issue, and at the same time I am quite frustrated that no one ever bothered to mark the module as deprecated or 'work in progress' or 'unstable', for 7 years.

@CodeHotel
Copy link
Contributor

I have submitted Pr #3898, which fixes the immediate build issue.
A readily available fix can be done in Release 4.11.0 by using my fork's fix branch https://github.com/CodeHotel/opencv_contrib/tree/matlab-build-fix-4.11.0

Fix in other versions may also work for 4.x releases, by cloning my repository and replacing the official repository's CMakeLists.txt and bridge.hpp with my fork's.

@CodeHotel
Copy link
Contributor

@asmorkalov Could this issue be closed, as it has been resolved in PR #3898 ?

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

No branches or pull requests

3 participants