Ask Your Question

Bindings to access openCV from MATLAB do not generate

asked 2015-02-11 11:48:53 -0500

talby gravatar image

updated 2015-02-13 16:07:41 -0500

WAS ORIGINALLY: "MATLAB bindings will not be generated". Reason to edit the question header text: I changed the question header text after having learned that I have to better distinguish between all the different available bindings.

The MATLAB "Not working" state persists.

The CMake-GUI configuration phase meanwhile terminates error message free for me.

Find below the original question, still serving as a blog on what I did and what I encountered so far:

Hello, I can't get the MATLAB bindings generated and search for your help. CMake throws the message:

    mex:                         C:/Program Files/MATLAB/R2014b/bin/mex.bat
    Compiler/generator:          Not working (bindings will not be generated)

I am running Win 7 Pro 64 bit, the current versions (all downloaded yesterday (11th Feb 2015)) of openCV 3.0 Beta, Python 3.4.2 and CMake 3.1.2, and have installed and running MATLAB R2014b 64 bit and the Windows SDK7.1 for providing the compilers. I have not Visual Studio installed, because I do not find a free-of-cost "Express" version on the MS site anymore. The new "Community" version is not listed as a MATLAB compatible choice on THE MATHWORKS site. So I prefer to stay with the SDK, which anyway contains all compilers and tools of the VS, and seems to mainly differ only in excluding to provide the Visual Studio IDE and some very advanced software development tools.

I confirmed that I can in MATLAB compile MEX files with the SDK provided compiler.

I start from the SDK Command Prompt (this is needed to avoid that SDK path variables and SDK registry keys are missing when CMake connects to the compiler) the CMake-GUI, and configure the Visual Studio 10 2010 Win64 compiler, with the option set to use default native compilers. In the SDK Command Prompt I also tried to first use the SetEnv command to already there set the target as /Release X64 Win 7 . Well, so far I can't overcome the message mentioned above, and after 2 days of exhausting searches in the internet I kindly ask for your help: Any idea what I shall try next? Thanks!

EDIT I: I meanwhile found out that in the openCV 3.0 Beta distribution the CMakeLists.txt or openCVFindMatlab.cmake files might not be complete: The following is an excerpt from the CMakeLists.txt file, around line 1064:

status("  Matlab:")
status("    mex:"         MATLAB_MEX_SCRIPT  THEN  "${MATLAB_MEX_SCRIPT}"   ELSE NO)
  status("    Compiler/generator:" MEX_WORKS    THEN  "Working"                ELSE "Not working (bindings will not be generated)")

The variable MEX_WORKS only becomes mentioned in the above cited CMakeLists.txt line 1064, and of course then has to produce, as not existent, the message "Not working". While in the file OpenCVFindMatlab.cmake it can be found in lines 160, 161, 167, and 169 that MATLAB_MEX_SCRIPT becomes generated, no code (I searched for the string "MEX_WORKS" in all files in the source directory) could be found concerning MEX_WORKS. Am I wrong ? Any help is appreciated!

EDIT II: I ... (more)

edit retag flag offensive close merge delete


related to this issue ?

berak gravatar imageberak ( 2015-02-11 11:59:49 -0500 )edit

I guess that it is not related to that problem, I at least haven´t encountered that particular error message by now. The bad message which I received can already be found in the log file written by CMake during the configuration phase. I then did not start to actually "generate", because it is already clear that the outcome would not be what I want. Maybe I will run into that problem later, then. Well, I now first would like to step forward in the configuration phase and will see what comes up next afterwards. Anyway, thanks for you hint!

talby gravatar imagetalby ( 2015-02-11 16:04:40 -0500 )edit

After some very long search I finally found, that the openCV bindings for MATLAB are just not part of the ready to download openCV 3.0 Beta distribution, but have to be found in an opencv_contrib branch here: . Sorry for having bothered you.

talby gravatar imagetalby ( 2015-02-12 10:39:21 -0500 )edit

And yes, now I hit into the same issue as @berak .

talby gravatar imagetalby ( 2015-02-12 12:18:44 -0500 )edit

well, in the long run, @hiltonbristow will have to come around and fix it.

if you're bold, and got some basic python skills, you could try on your own:

basically try to comment lines 32, 37-41, 59,60,61

(you won't get any docs this way, but even if the rst-parser still existed, it would not be able to extract any inline docs anymore, since they were all converted to doxygen tags)

((and no, have not tried exactly this (no matlab here))

berak gravatar imageberak ( 2015-02-12 12:59:32 -0500 )edit

@berak The developers are most likely already aware about it, as it is mentioned here . Also, trying to build openCV with the bindings to use it from MATLAB this morning didn't throw that error to me anymore, instead I am now facing a new one. I have to guess that the new error occures even before hitting the issue which you made me aware about, because the topic of your issue is not marked to have been worked on, at the github page. I updated my question above according to my new problem, and put the most up-to-date information to the bottom of that post.

talby gravatar imagetalby ( 2015-02-13 11:45:20 -0500 )edit

well, for / the rsr_parser deps, you could try out, if commenting above mentionend lines would help, maybe even do a pullreq. to help the next one trying this.

sorry, no idea, why the test fails with cmake. but again, it looks like it's only the test, not the main module

berak gravatar imageberak ( 2015-02-13 12:06:46 -0500 )edit

2 answers

Sort by » oldest newest most voted

answered 2015-02-13 13:00:48 -0500

anuppari gravatar image

As I mentioned here , you can download the from an old commit of opencv. Once I put that in the corresponding folder, I was able to generate matlab bindings. I pretty much followed the instructions here: with a few modifications. I downloaded the matlab module from the opencv_contrib (which you have now done) since they are not in the standard opencv and used Visual Studio Pro 2013 (VS12) to compile since VS2010 was giving me errors about missing the headers and ambiguous calls to standard functions. Also, the correct folder to put into the $PATH environment variable is [path_to_opencv]/build/x64/vc12/bin

edit flag offensive delete link more


oh, nice, that it worked for you, but still, it would be much better, if the script would be updated.

do you think, you can do that ?

berak gravatar imageberak ( 2015-02-13 14:42:09 -0500 )edit

Anuppari, thanks a lot for your information. I meanwhile can't reproduce any of my error messages anymore! The cmake-gui configuration now terminates error free, the MATLAB "not working" state persists, though. I did a lot of things, and thought to have tested to undo all of them, but can't figure out what actually overcome the error messages. Probably new source downloads run again this noon helped. I don't have the files from the morning, yesterday and the day before anymore. As I didn't find any pull requests indicating so, is it possible that sombody updates github repositories without this beeing highlighted in a status message or pull request message?

talby gravatar imagetalby ( 2015-02-13 15:47:43 -0500 )edit

Hi would you bother to share that old somewhere? github no longer keeps that file, it's nowhere to be found :(

yifita gravatar imageyifita ( 2015-04-18 09:51:45 -0500 )edit GitHub remembers everything

mshabunin gravatar imagemshabunin ( 2015-06-19 08:09:48 -0500 )edit

answered 2015-06-19 05:14:57 -0500

Wajahat gravatar image

I solved it following the steps below:

1- Downloaded OpenCV extra modules from :

2- Following the steps on the page i.e. in CMAKE GUI:

a) Goto OPENCV_EXTRA_MODULES_PATH and set the path to .....opencv_contrib-master\modules

b) configure again and now it shows :


mex: c:/Program Files/Matlab/R2014b/bin/mex.bat

Compiler/generator: Working

edit flag offensive delete link more


This is the answer! It works on Linux too! Thanks a lot and +1 from me.

rbaleksandar gravatar imagerbaleksandar ( 2015-12-03 16:43:34 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-02-11 11:48:53 -0500

Seen: 3,440 times

Last updated: Jun 19 '15