Error using vl_gmm - Attempt to execute script as function - matlab

Hello I want to use Fisher Vector for my SIFT descriptors. I tried to use the function from VL_FEAT. I added the directory in MATLAB and also run vl_startup. It runs successfully but when I try the example
It gives me this error:
Attempt to execute SCRIPT vl_gmm as a function:
C:\vlfeat-0.9.19.tar\vlfeat-0.9.19\vlfeat-0.9.19\toolbox\gmm\vl_gmm.m
Anyone help me how can i solve this?

I have a couple of suggestions for you to get VLFeat working. I'm not sure if you have tried them all, but I will suggest them as we go:
Suggestion #1 - Compiling VLFeat if you downloaded just the source
Did you only download the source files? If you did, did you compile VLFeat first? Specifically, did you run vl_compile first when you downloaded the source?
Functions like vl_gmm require a MEX wrapper to be compiled before you can use the function. If you look in the toolbox/gmm directory, there are two files: vl_gmm.m and vl_gmm.c. vl_gmm.m is simply a MATLAB file that contains the documentation on how to use the function. The actual function is in vl_gmm.c and it is a MEX file. You only get this error if you didn't compile VLFeat first because it's trying to run the .m file by default, which contains nothing but documentation.
As such, make sure you compile VLFeat by running the vl_compile.m script before trying to run your example.
Suggestion #2 - Download the pre-compiled binaries
Alternatively, you can get VLFeat pre-compiled by downloading the binaries: http://www.vlfeat.org/download/vlfeat-0.9.19-bin.tar.gz . If you have trouble compiling the libraries, then download the actual pre-compiled binaries through the link I gave you, then try running vl_setup.m from there.

Related

mcc producing an unresponsive executable

I am trying to compile a Matlab function using the mcc function. My function writes a line of text to a file.
function hello()
ofid = fopen('hello.txt','w');
fprintf(ofid, 'Hello there, this is matlab.\n');
fclose(ofid);
end
It runs as expected when called from the Matlab console. However, when I compile the file to an executable using mcc
/opt/matlab/matlab2008a/bin/mcc -m hello.m
and run it as
./hello
It seems to run forever and produces no hello.txt file. Both the executable as well as the Matlab function files are in the Matlab working directory.
I am unable to see what can be possibly wrong in my use of mcc. Please help.
Typically, you need to setup the MATLAB runtime environment when executing mcc compiled applications.
You'll probably get more mileage the first time by using deploytool (from the command line) to compile your hello.m program here. MATLAB's application builder will produce a run_hello.sh file that you can peruse through to see how they setup their libraries. Then, to execute your program you would actually call it like this:
./run_hello.sh /Applications/MATLAB/MATLAB_Runtime/v90/
Note: I have just included a generic location for the MATLAB runtime environment, but the actual location will vary depending on your platform and version of MATLAB you built the application with.

mex file not executing in MATLAB 7.5.0 (R2007b)

I created a .mex file of a MATLAB file test.m from MATLAB R2012b using MATLAB coder.
I got the output file test_mex.mexa64. I was hoping to use this .mex file in MATLAB 7.5.0 (R2007b) but it shows the following error.
Invalid MEX-file '/work/sreekanthl/test_mex.mexa64': libmwblascompat32.so:
cannot open shared object file: No such file or directory.
How can I make this .mex file work in 7.5.0 (R2007b)?
I agree with David Kelley's answer for general MEX files but there is a special consideration for MATLAB Coder generated MEX files. MATLAB Coder generated MEX code is expected to be forward compatible but generally is not expected to be backward compatible. In other words, you are expected to be able to use such MEX code in a newer release than the one with which it was generated, however using the code in an earlier release cannot be guaranteed to work.
The reason for this is that the MEX code uses various runtime libraries which ship with MATLAB. These libraries advance over time and the MEX file from the newer version may depend on features that the older libraries do not provide, or even on a new library which does not exist in the older release as you are seeing here.
If you want to create MEX code that is compatible with earlier releases, you could generate a standalone target such as a static library or a shared library (LIB or DLL respectively for MATLAB Coder), and either:
Try to use loadlibrary to call the generated code in MATLAB
Write a generic MEX interface for it and compile that MEX code in the older release
These options are more work but should enable you to create a MEX file or shared library usable in an older release.
While TMW says that mex functions are usually compatible between versions, it's not officially supported and quite common to run into issues with it.
The only reliable option is to simply recompile the generated source code that Matlab coder created (i.e., the C code) in the version you want to run it in using the mex function.

Calling pdftops does not work in Matlab

I want to use the export_fig package for Matlab. At one point this worked, but now it's broken. The error occurs here:
>> system('pdftops -h')
dyld: Library not loaded: /opt/local/lib/libtiff.5.dylib
Referenced from: /opt/local/bin/pdftops
Reason: Incompatible library version: pdftops requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
pdftops -h: Trace/breakpoint trap
But when I call pdftops from my own bash terminal everything works fine. I suppose it must be because Matlab has some bad library paths or something, but I don't know where to go from here?
Some relevant environmental vars used by matlab:
>> system('env')
SHELL=/bin/bash
OSG_LD_LIBRARY_PATH=/Applications/MATLAB_R2013b.app/sys/openscenegraph/lib/maci64
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin
__CHECKFIX1436934=1
XFILESEARCHPATH=/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/locale/%L/%T/%N%S:
DYLD_FRAMEWORK_PATH=/Applications/MATLAB_R2013b.app/sys/os/maci64:/Applications/MATLAB_R2013b.app/bin/maci64/../../Contents/MacOS:/Applications/MATLAB_R2013b.app/bin/maci64:/Applications/MATLAB_R2013b.app/extern/lib/maci64:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./native_threads:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./server:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./lib/jli
SHLVL=1
__KMP_REGISTERED_LIB_33586=0x124404710-cafeb339-libiomp5.dylib
DYLD_LIBRARY_PATH=/Applications/MATLAB_R2013b.app/sys/os/maci64:/Applications/MATLAB_R2013b.app/bin/maci64/../../Contents/MacOS:/Applications/MATLAB_R2013b.app/bin/maci64:/Applications/MATLAB_R2013b.app/extern/lib/maci64:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./native_threads:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./server:/Applications/MATLAB_R2013b.app/sys/java/jre/maci64/jre/lib/./lib/jli
If you take a look at the error message, MATLAB uses libtiff to call pdftops, but only has version 6.0.0. It says it needs version 8.0.0 or later. There has been a case where this happened before here on StackOverflow. Someone was trying to install mexopencv and has encountered the same error that you're talking about: Compiling mexopencv in OS X 10.9 with Xcode 5 and Matlab R2013b
Though this is unrelated to what you're doing, they encountered the libtiff error that you speak of. They provide two solutions how to fix this error:
Go into MATLAB's root directory, then go bin/os directory where os is the directory of the operating system you are using (in my case, it's maci64). To get into the root directory, in the command prompt do this: cd/(matlabroot). Once you're here, locate the libtiff.5.dylib file and rename it to something like libtiff.5.dylib.bak so that the libtiff libraries that are used are the ones that are default to your system rather than what MATLAB is using internally in the program.
Force MATLAB to point to the library that is part of the system rather than using the one built into MATLAB. As such, in MATLAB's command prompt, run this command:
setenv('DYLD_INSERT_LIBRARIES','/opt/local/lib/libtiff.5.dylib');
Once you do this, you may get further errors that are similar but are with other libraries. As such, you need to keep appending these libraries in the second parameter of setenv and colon-delimiting them until you resolve the issues. You need to make sure that you're pointing to the ones on your system rather than the ones installed with MATLAB. In your case, you have to do:
setenv('DYLD_INSERT_LIBRARIES', ...
'/opt/local/lib/libtiff.5.dylib:/opt/local/lib/l‌​ibcurl.4.dylib');
Glad this helped!

how to use opencv and engine.h

can you give me a basic c++ code that inclue opencv libraries , and can call the matlab engine ?
the file should compile using matlab mex.
(my problem is when I use the engine and compile it with "mex -f optionfile file.cpp"I get error message "cannot include opencv\cv.h" , but using the opencv without the engine its work using the mex file.xpp)
You need Matlab engine if you want to run .m files outside of Matlab command window (e.g. bash, c++ source file, etc.)
In your case, mex program (Matlab External Interface which acts like g++ or other c++ compilers) is required to compile a c++ source file. You must provide mex program a source file which is written according to what Matlab has introduced in its documentation.
If your source code (.cpp file) is including opencv/cv.h file and using one of its methods, you need to link the appropriate library (say libopencv.so, libopencv.dll or etc,) using -l flag. (I use mex foo.cpp -l opencv_core)
I hope it helps, you can provide your source

Linking MATLAB to a DLL library

I am trying to execute some example code from a MATLAB toolkit, 'oscmex'. This toolkit allows for communication using the OSC protocol over MATLAB. I presume this question is non-specific; it should apply to any toolkit that is set-up in the manner that this one is.
Reasons aside, I'm having some simple trouble getting the toolkit up and running. The toolkit comes with no documentation whatsoever; just a set of six DLL files (in one directory), and a set of four MATLAB '.m' example code files (in another directory). Every toolkit I've used in the past has either been a built-in kit or has had an intuitive (semi-automated) install procedure.
After downloading the toolkit, the first thing I tried was to simply run one of the '.M' example codes. This failed as the first line of the code contained the function osc(), which is not (currently) recognised by MATLAB.
So, I figured maybe I need to move the '.M' files into the same folder as the DLLs; perhaps MATLAB would see the functions inside the DLLs. No dice.
So, I realise that I have to somehow link MATLAB to the DLLs on startup. I tried adding the DLLs to a folder and adding an entry to that in the 'pathdef.m' file. This also failed.
I've read somewhere I can load a DLL file by using the loadlibrary() function. So, I tried doing this for the DLL files. This failed on the first file:
>> loadlibrary('osc_free_address.dll')
Error using loadlibrary>lFullPath (line 587)
Could not find file osc_free_address.h.
I'm starting to run out of options... How can I get this set of DLLs up and running?
Browsing this library's web page it would seems these DLLs are just old form of mex files.
Therefore, they should not be used in the context of shared library (e.g., using loadlibrary and calllib), but rather compiled directly to mex files.
To do so, I would suggest the following steps:
Make sure you have a working mex compiler configured for your Matlab.
In matlab, type:
>> mex -setup
this will guide you through the configuration process. I understand that you are working on a windows machine, I usually work with visual studio compiler - works best for me.
This library's README file suggests that OSC
requires liblo 0.22 or later. See http://plugin.org.uk/liblo/
Make sure you have this library and it is located in you LD_LIBRARY_PATH (see e.g., this question for details, or the mex docs).
Get the source code for OSC library from their repository.
Compile the sources in matlab using
>> mex -O -largeArrayDims osc_free_address.c
>> mex -O -largeArrayDims osc_free_server.c
and so on for all 7 c source files. After mex-ing the c files you'll have mex files that you can run from Matlab as if they were regular functions.
You may find it useful to use the library's make file, as suggested by Andrew Mao.
Good luck,
If you look at the build for that software, it is compiling mex files, not DLLs (shared libraries): http://sourceforge.net/p/oscmex/code/4/tree/trunk/src/osc_make.m.
I would try using the mex commands instead of the dll commands (perhaps the files are just misnamed.) Even better, I would compile the files yourself with mex using the build file in source.
Note that the instructions also say that you need liblo-0.22 in order to run the library, so make sure you have that accessible as well.
I took a look at your OSC Toolkit. It seems they have been compiled by MATLAB mex. But, it is not mentioned for which kind of architecture they have been built. You can type mexext at MATLAB command prompt to find the extension for your MATLAB mex files. Then, change the DLL extensions to the given extension. If the original mex is compatible with your matlab, the DLL can be easily accessed by MATLAB. Just make sure to add the folder to your MATLAB path.
Try changing the extension from .dll to .mexw32 (in win32), or .wexw64 (in win64). It's a long shot but it might work.
The Shared Libraries cannot be used directly. As you have mentioned, you need to load them into MATLAB using loadlibrary. According to the documentation, loadlibrary takes two arguments (at least). The first argument is the name of the file, and the second one is the header file which contains definition of functions and external variables. If you do not provide the header file, the MATLAB looks for the a file with the same name as the DLL. Having said that, you need to have access to the header file or at least if you know how the function looks like, you need to write a header for the DLL.
I have worked with the DLLs in MATLAB. The MATLAB is not very user-friendly as long as DLL is concerned. Especially, if the DLL is written in a language other than C (or C++) you will have trouble loading the function into MATLAB.
Besides, MATLAB can only support some specific DLLs. Based, on your version of MATLAB, you need to find out whether or not the shared library is supported by MATLAB. Have a look at Here
In a nutshell, it is not easy to load a DLL into MATLAB. You need to have some information from DLL.