Giter Club home page Giter Club logo

Comments (6)

kyamagu avatar kyamagu commented on July 18, 2024

Sounds like an issue in the way you set up PATH. I have totally no idea how MCR works, but is there any way to check PATH within your compiled executable? Like calling getenv?

from mexopencv.

gargeug avatar gargeug commented on July 18, 2024

Yeah, I am calling getenv from within the script, appending my relative DLL folder path, and then setting the new path. I don't think it is a PATH mistake as on my development machine I have the OpenCVs installed DLL path '.../vc10/bin' hardwired into my system. And when I run the script from MATLAB on my dev comp, it works fine -> it finds the DLLs. But then the .exe throws the invalid MEX function error on my dev comp, even though the hardwired OpenCV install DLL path '.../vc10/bin' still exists in the PATH environment, in addition to the './DLLs' I am now adding programmatically.

from mexopencv.

gargeug avatar gargeug commented on July 18, 2024

Further, I have installed MATLAB on a clean target machine with no opencv or visual studio compiler. When I setup a folder with the './DLLs' and './mexopencv-master' paths below the m file and run it in MATLAB, it works fine. This tells me that the programmatic adding of that relative DLL path to the system PATH is working correctly, as on this target there are no openCV DLL paths hardwired into the machine.

BTW, sorry for closing this. I hit the wrong button.

from mexopencv.

amroamroamro avatar amroamroamro commented on July 18, 2024

may i ask, what exactly is the error message? perhaps the target machine is missing the visual c++ redistributables

from mexopencv.

amroamroamro avatar amroamroamro commented on July 18, 2024

Disregard my last comment. I tested this myself, and I can say for sure this is a PATH issue.

First lets make sure we are on the same page. There are several "path" we need to manage: internal MATLAB path, external system path (system environment variable).

Before building the example, I have added mexopencv to the MATLAB path, and added opencv bin directory to the system-wide Windows PATH.

>> addpath('...')

C:\> echo %PATH%

Using "deploytool", I created a windows application, using the "classification_demo.m" script found in the sample folder of mexopencv. Once compiled, I ran the generated .exe file in command prompt, and it ran successfully.
Next, I removed OpenCV bin directory from the PATH variable, and reran the executable. I get the following error:

C:\Documents and Settings\Amro\Desktop\cv\test_mexcv\distrib>No log file specified
Invalid MEX-file 'C:\DOCUME~1\Amro\LOCALS~1\Temp\Amro\mcrCache8.0\test_m0\Documents and Settings\Amro\Desktop\mexopencv\+cv\private\ANN_MLP_.mexw32': The specified module could not be found.
Error in cv.ANN_MLP (line 113)

Error in classification_demo (line 19)

MATLAB:invalidMEXFile

Note that if you want your built .exe to find the required DLLs, they have to be added to the PATH env. var. on a system-wide level, or simply copy all OpenCV DLLs to the same directory as your executable.

A good way to troubleshoot dll issues is using the dependency walker tool. Load the executable from before, then from the Profile menu, select 'start profiling'. Once finished, inspect the generated log at the bottom for any problems.
Note that you will not see all the dependencies at first. The way the MATLAB compiler works is by bundling all you files (M-files, MEX-files, ..) encrypted into the output .exe, and it is not until you run the file that these are extracted and executed by the MCR.

This was tested on WinXP 32-bit, MATLAB R2012b, OpenCV 2.4.3, mexopencv compiled with VS2010

from mexopencv.

gargeug avatar gargeug commented on July 18, 2024

Well f me. It was a PATH issue, but only in my compilation. I didn't realize that the MATLAB compiler needs all of the DLLs AND .mexw64 files at the same level as main when compiling because in runtime it expands the .exe into a temporary folder in which all relative paths no longer exist, and so searching for the './mexopencv-master' folder containing the .mexw64 files was what was returning the Invalid MEX-function error. By compiling with everything at the main.m level and removing all addpaths(...), I was able to successfully run the .exe on both my dev comp, and target machine which has no compiler or anything on there.

Thanks everyone for the help, and sorry to disturb you with this question. I learned a lot about compilers today. And thank for this wonderful tool that is mexopencv.

from mexopencv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.