Mex compilation with opencv libraries

Hello

I have a need to acquire and process images from a "Point Grey Research Chameleon"  camera in MATLAB. I do not have the Image Acquisition Toolbox, however, I do have some C++ code making use of functions in OpenCV to do the acquisition and have been successful in compiling a C++ MEX file to get images into Matlab.

 I have been developing my program further and making use of a particular OpenCV function "cvCreateImage" which results in a compilation error as follows:

g++ -Wall -fPIC -ansi -pthread -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I/home/$USER$/matlab/extern/include -I/usr/local/include/opencv  -c test2.cpp
test2.cpp: In function ‘void mexFunction(int, mxArray**, int, const mxArray**)’:
test2.cpp:32: warning: unused variable ‘frame_undistorted’
test2.cpp:39: warning: unused variable ‘intrinsic’
test2.cpp:40: warning: unused variable ‘distortion’
test2.cpp:48: warning: unused variable ‘mapx’
/home/$USER$/matlab/bin/mex -cxx CC='g++' CXX='g++' LD='g++' -L/usr/local/lib -lm -lcv -lhighgui -lcvaux -output test2 test2.o
test2.o: In function `mexFunction':
test2.cpp:(.text+0xe7): undefined reference to `cvCreateImage'
collect2: ld returned 1 exit status

    mex: link of ' "test2.mexglx"' failed.

make: *** [test2.mexglx] Error 1



My system is running Ubuntu 9.04 and I'm using the following makefile to compile the code:


MEXSUFFIX  = mexglx
MATLABHOME = /home/$USER$/matlab
MEX        = $(MATLABHOME)/bin/mex
CXX        = g++
CFLAGS     = -Wall -fPIC -ansi -pthread -DMX_COMPAT_32 -DMATLAB_MEX_FILE

LIBS      = -L/usr/local/lib -lm -lcv -lhighgui -lcvaux
INCLUDE   = -I$(MATLABHOME)/extern/include -I/usr/local/include/opencv 
MEXFLAGS  = -cxx CC='$(CXX)' CXX='$(CXX)' LD='$(CXX)'
FILE      = test2
  
$(FILE).$(MEXSUFFIX): $(FILE).o
	$(MEX) $(MEXFLAGS) $(LIBS) -output $(FILE) $^

$(FILE).o: $(FILE).cpp
	$(CXX) $(CFLAGS) $(INCLUDE) -c $^

clean:
	rm -rf *.o *.mexglx *.bmp *.csv


Now if I compile just using g++ and don't have anything to do with Matlab it compiles fine. The corresponding makefile is as follows:

CC = g++

CFLAGS = -Wall

LIBS = -L /usr/local/lib -lm -lcv -lhighgui -lcvaux 
INC = -I/usr/local/include/opencv 

FILE = test2

${FILE} : ${FILE}.o
	${CC} ${CFLAGS} ${OBJS} ${LIBS} ${FILE}.o -o ${FILE}

${FILE}.o: ${FILE}.cpp
	${CC} ${CFLAGS} ${INC} -c ${FILE}.cpp
 
It seems there is some MATLAB related issue causing the linking error. Any ideas on how to fix this?

Cheers

Fin
0
Fin
1/20/2010 11:03:05 PM
comp.soft-sys.matlab 208962 articles. 11 followers. lunamoonmoon (258) is leader. Post Follow

1 Replies
757 Views

Similar Articles

[PageSpeed] 31

I am having the same problem . Have you found the solution ??

"Fin Raziel" wrote in message <hj8239$e7s$1@fred.mathworks.com>...
> Hello
> 
> I have a need to acquire and process images from a "Point Grey Research Chameleon"  camera in MATLAB. I do not have the Image Acquisition Toolbox, however, I do have some C++ code making use of functions in OpenCV to do the acquisition and have been successful in compiling a C++ MEX file to get images into Matlab.
> 
>  I have been developing my program further and making use of a particular OpenCV function "cvCreateImage" which results in a compilation error as follows:
> 
> g++ -Wall -fPIC -ansi -pthread -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I/home/$USER$/matlab/extern/include -I/usr/local/include/opencv  -c test2.cpp
> test2.cpp: In function &#8216;void mexFunction(int, mxArray**, int, const mxArray**)&#8217;:
> test2.cpp:32: warning: unused variable &#8216;frame_undistorted&#8217;
> test2.cpp:39: warning: unused variable &#8216;intrinsic&#8217;
> test2.cpp:40: warning: unused variable &#8216;distortion&#8217;
> test2.cpp:48: warning: unused variable &#8216;mapx&#8217;
> /home/$USER$/matlab/bin/mex -cxx CC='g++' CXX='g++' LD='g++' -L/usr/local/lib -lm -lcv -lhighgui -lcvaux -output test2 test2.o
> test2.o: In function `mexFunction':
> test2.cpp:(.text+0xe7): undefined reference to `cvCreateImage'
> collect2: ld returned 1 exit status
> 
>     mex: link of ' "test2.mexglx"' failed.
> 
> make: *** [test2.mexglx] Error 1
> 
> 
> 
> My system is running Ubuntu 9.04 and I'm using the following makefile to compile the code:
> 
> 
> MEXSUFFIX  = mexglx
> MATLABHOME = /home/$USER$/matlab
> MEX        = $(MATLABHOME)/bin/mex
> CXX        = g++
> CFLAGS     = -Wall -fPIC -ansi -pthread -DMX_COMPAT_32 -DMATLAB_MEX_FILE
> 
> LIBS      = -L/usr/local/lib -lm -lcv -lhighgui -lcvaux
> INCLUDE   = -I$(MATLABHOME)/extern/include -I/usr/local/include/opencv 
> MEXFLAGS  = -cxx CC='$(CXX)' CXX='$(CXX)' LD='$(CXX)'
> FILE      = test2
>   
> $(FILE).$(MEXSUFFIX): $(FILE).o
> 	$(MEX) $(MEXFLAGS) $(LIBS) -output $(FILE) $^
> 
> $(FILE).o: $(FILE).cpp
> 	$(CXX) $(CFLAGS) $(INCLUDE) -c $^
> 
> clean:
> 	rm -rf *.o *.mexglx *.bmp *.csv
> 
> 
> Now if I compile just using g++ and don't have anything to do with Matlab it compiles fine. The corresponding makefile is as follows:
> 
> CC = g++
> 
> CFLAGS = -Wall
> 
> LIBS = -L /usr/local/lib -lm -lcv -lhighgui -lcvaux 
> INC = -I/usr/local/include/opencv 
> 
> FILE = test2
> 
> ${FILE} : ${FILE}.o
> 	${CC} ${CFLAGS} ${OBJS} ${LIBS} ${FILE}.o -o ${FILE}
> 
> ${FILE}.o: ${FILE}.cpp
> 	${CC} ${CFLAGS} ${INC} -c ${FILE}.cpp
>  
> It seems there is some MATLAB related issue causing the linking error. Any ideas on how to fix this?
> 
> Cheers
> 
> Fin
0
6/3/2011 6:47:04 PM
Reply:

Similar Artilces:

Linking problem compiling Mex with Matlab and FFTW library
Hi everyone, I want to speed up my Matlab program which uses many FFT operation by writing a mex file and using FFTW library. What i've done so far: - installed Microsoft Visual Studio 2008 - choose it via "mex -setup" in Matlab - downloaded the latest FFTW and created the *.lib files according to this Tutorial: http://www.math.ucla.edu/~anderson/270e.1.08f/FFTW/ObtainingFFTW3.html - added a static path "G:\FFTW\fftw-3.2.2-dll64" to the PATH, INCLUDE and LIB in the "mexopts.bat" in the directory returned by the MATLAB command "prefdir" - I used ht...

I have a m-file that I compiled into a dll using MatLab compiler. I then created a C# library class to call the MatLab dll
hi, >i creat an M-file which has an imagen in file then in matlab i create it dll using >deploytool >Then i include this dll in visual studio 2005 C#.Net project >Then i make a windows form which has a button,picturebox,textbox openfiledialog >what should be the code of button it access the m-file from matlab show its path in >textbox and image in picture box or >what is the procedure of accesing matlab file from C#.Net,plz help me for this >problem immediatley >my code of m-file is function aa %Ori_Face=imread('E:\Shakir\Faisal\Face\sub6.1.jpg'); ...

USE Shared Matlab Compiled Library IN C Mex File
I have the fallowing problem I want to use certain time consuming matlab functions in C/C++ with other c++ Librarys IN an MEX File which I can start in Matlab. I compiled with MCR the time consuming matlab functions too a shared library and want to use them now in a mex file... (Up to now I have linking problems in the MEX file) I have read the fallowing in the forum: It is not possible to incorporate Matlab compiled file into mex, because there is a conflict between MCR and Matlab. Is this really correct? Is there a way of doing this, or do I need to start the application direct...

error MEX: Compile C++ file with external library (matlab)
Dear all, I have the following problem: - I have a file (mexRVO.cpp) with C++ code addapted to mex. - This file contains the include: #include "RVOSimulator.h", which is located in the same folder and contains the declarations of several functions from a library. - The library is rvo_d.lib and can also be found in the same folder. I've tried to compile both with: mex mexRVO.cpp and mex mexRVO.cpp rvo_d.lib Both of them returned the same errors: Creating library C:\USERS\ADMIN\APPDATA\LOCAL\TEMP\MEX_GA~1\templib.x and object ...

Matlab Object compile to library (compiler 4)
Hi, I wonder if someone has the experience of compiling a matlab object into a dll. I implemented a class in which I would like to use it in my C++ code. However, I don't want the class being instantiated multiple times whenever I make calls to the library. Is there a way to do the following: - Create a wrapper for the class instantiation, return the address of the object to the caller - Create other wrappers that accept the object address as argument and use it to call the object methods - caller can now reuse the object as many times as he wants. - destroy the object when finish Does ...

Compiling labca against matlab libraries. Missing library?
Hi all, I'm compiling labca (Channel Access) against the libraries in /cygdrive/c/Program Files/MATLAB/R2008a/extern/lib/win32/microsoft (as you can see I'm doing this in cygwin and compiling against R2008a), but it errors out due to a missing library -- libut.lib. There are plenty of other libs in that directory, but not libut.lib. I've searched my hdd for this lib, but it can't be found anywhere -- it only finds libut.dll in C:\Program Files\MATLAB\R2008a\bin\win32 Is this a standard matlab library, and, if so, why is it missing on my fresh matlab installation? Can anyone...

mex compiling C++ code with external static libraries on older versions of Matlab (7.0.0....)
I have used this line when building C++ code to create a mex file: mex -L -lblas_win32 -llapack_win32 needle3D.cpp needle.cpp matrix.cpp interaction.cpp mesh.cpp ... tissue.cpp utils.cpp coordinates.cpp This syntax works when I used it on Matlab R2008b. However, this syntax doesn't work when I used it on a machine that has Matlab 7.0.0. It appears that the syntax have changed, and I have some trouble changing the line. What would you suggest changing them to for the line to work with the latter version? What would be the best way to check the version? On Jan 15, 4:46=A0pm, checkmate...

matlab crashes (win 7 64 bit) without messages, logs or dumps while using mex-files linked with itpp library and compiled with mingw
Hello, I know, that this a very special problem and I would like to provide an error log or something like this, but this is the problem. Following situation: Matlab 2010a (64bit) on Win 7 64bit Enterprise Mingw-w64 with basis msys environment used modified gnumex to create .def and .lib files mexopt.bat modified to work with mingw This setup works perfectly. I can write,compile,link and run mex files. Moreover, I compiled the itpp library with msys/mingw and created static libs as well as shared libs. Now, the problem: At the point, when I include an itpp related class of fu...

C Shared Library Example:: Libraries (MATLAB Compiler)
Hi, I compiled the "addmatrix.m, multiplymatrix.m, eigmatrix.m" from "C:\MATLAB701\extern\examples\compiler\" directory as given in the README file. I use the command "mcc -B csharedlib:libmatrix addmatrix.m multiplymatrix.m eigmatrix.m -v" as given in the "C Shared Library Example" in "help". There is no file "libmatrix.dll" and "libmatrix.lib" created after compilation. All other files (.c,.h,.exports, .ctf) are created. Without "libmatrix.lib" the "matrixdriver.c" is giving the linking error. Cou...

Trying to compile C++ code with Matlabs MEX compiler
Hi After successful compilation of unaltered mexcpp.cpp example c++ code from Matlab (C:\MATLAB6p5\extern\examples\mex) I would like to use some functions of a dll. (headerfile.dll) (Sorry about name conventions) When trying to include a header file on mexcpp.cpp #include "headerfile.h" the compiler, called from matlab, sends the following errors: C:\MATLAB6p5\work\Include\headerfile.h(18) : error C2146: syntax error : missing ';' before identifier 'FunctionsName' C:\MATLAB6p5\work\Include\headerfile.h(18) : fatal error C1004: unexpected end of file found #ifnde...

Calling matlab compiled shared library in matlab console
Hi everyone, I wonder if anyone has tried to call a shared library compiled using matlab compiler 4 within matlab? I did this because it is easier to debug within matlab since all my code is in matlab. I can then provide the library for others to use after I fully debug the library. Any help will be appreciated. Thanks. Jerry ...

mbuild vs. mex pre-compiling in MATLAB Compiler projects
I am seeing different behavior when a mex file is compiled using mbuild (as part of a larger MATLAB compiler project) as compared to when it is compiled individually using mex(). One way to include a mex file in the building of a standalone is to pre-compile it from the command line using the mex command and then to add the mex file manually to the list of dependent files. When I take this approach, mex() completes the compilation without errors and, when I run a project build, everything works fine and the resulting standalone .exe performs as desired. If however, I replace one of the ...

matlab mex compiler
what is the default matlab c mex compiler ? ss wrote: > > > what is the default matlab c mex compiler ? lcc is the standard free compiler delivered with matlab (see <http://www.cs.virginia.edu/~lcc-win32/> or more information). But if you prefer to use Visual C, Watcom and have it installed (for compiling C++ for example, lcc can't), just type 'mex -setup' to reconfigure the standard compiler that is to be used. best regards, D. Fricker ss <ss@ss.com> writes: > what is the default matlab c mex compiler ? There is no such thing. See http://www.mathwork...

uint32 doesn't work in shared library which is compiled using matlab compiler mcc
please help me ! I am currently converting matlab code to c++ in MSVC 2010. however, the following matlab commands doesn't work. => vertex(:,face(2,:)); so, I guessed face(2,:) might not be integer values. so, I added "face=int32(face)" line like this. => face=int32(face); <-- I guess int32 function doesn't work in a compiled library save('printf101.txt', 'face', '-append', '-ascii'); <-- it doen't give any output vertex(:,face(2,:)); <--- vertex and face array data received from c+...

Why can't Fortran-mex files be compiled on matlab V5.3 and run on matlab V6?
Hi, does anyone know why Fortran-mex files can't be compiled on matlab V5.3 and run on matlab V6? For example: if I compile the example-program (shipped with matlab) timestwo.f on matlab version 5.3 (R11) and try to run it on matlab version 6+ (R12 or R13), I get the error message: "Unable to load mex file: E:\timestwo.dll. The specified module could not be found. ??? Invalid MEX-file" Likewise if I compile it on matlab version 6.1 (R12), I get a similar error message if run on matlab version 5.3 (R11). However, if I run it on matlab version 6.5 it works OK. ...

Does anybody know a way to convert Matlab code into Fortran and then compile Fortran mex dll file for Matlab 2006a?
Hi all, I want to ask three questions regarding Fortran and Matlab interface. The two tools I am using are: Intel Visual Fortran 10.1 and Matlab 2006a. Q1. What is the best converter to convert Matlab code into Fortran code with readability? My understanding is that Fortran and Matlab are both vectorized and they should be pretty similar and such converter should do a good job. Q2. Is there a wizard for Intel Visual Fortran under MS Visual Studio.Net 2003 or Visual Studio.Net 2005 to set up environments for building mex dll file for Matlab on Windows XP? There is such a wizard tool for VC/C++, which is very convenient, just create a MEX project in Visual Studio and the compiled the result will be a mex dll for use in Matlab. I hope there is a similar tool for Fortran? Q3. Is there a tool to convert the Matlab code into Fortran with readability and then automatically make itself a mex dll? Thanks a lot! On Jul 6, 9:49 pm, "Linus Utopia" <linus_uto...@gmail.com> wrote: > Hi all, > > I want to ask three questions regarding Fortran and Matlab interface. The > two tools I am using are: Intel Visual Fortran 10.1 and Matlab 2006a. > > Q1. What is the best converter to convert Matlab code into Fortran code with > readability? My understanding is that Fortran and Matlab are both vectorized > and they should be pretty similar and such converter should do a good job. > > Q2. Is there a wizard for Intel Visual Fortran under ...

Problems with matlab compiled library
I am creating a c++ dll to use with program, and that dll calls functions from a matlab created dll. If the function from my matlab dll is self-contained (no input or output arguments) then everything works fine, but if I create mxArray variables to pass into a function with inputs, the c++ dll compiles fine, but the program I created it for cannot initialize and startup. I believe this is due to the fact that the other program loads MSVCR71.dll (microsoft visual c runtime library) and my matlab function loads MSVCR71d.dll (debug runtime). I'm 75% sure that this the problem. My question:...

Matlab Compiler with MEX functions..
Hello all, I am in the process of possibly buying the Matlab compiler so that I can distribute some of my Matlab code to customers without providing them with actual source code. I am wondering if anyone knows what will happen to MEX functions which are called from my Matlab code?? Does the Matlab compiler compile them into a DLL as well or is special handling needed? Thanks for any help you can provide me.. Sam "Samuel" <tard_288@yahoo.com> wrote in message <gvhp66$o3s$1@fred.mathworks.com>... > Hello all, > > I am in the process of possibly buying the...

MatLab compiled library is too slow
We are trying to implement some image analysis algorithms in MATLAB 7 and create a shared library that we can distribute with our application. Unfortunately, the shared library seems to run at half the speed of MATLAB itself. My colleague has told me that previous versions of MATLAB created compiled code that was up to 3 times faster than MATLAB itself. Why such a big loss in performance? I was looking through the support documents on Mathworks.com and it looks like the previous versions actually compiled M-code into C while the new version only creates a wrapper which executes the M-code. Is it possible to get an older version of the MATLAB compiler? Also, while debugging my application, I noticed that the M-code throws thousands of exceptions which are caught and handled. The code seems to execute properly, but I have to think that all that exception handling is hurting the performance. Any help or guidance would be appreciated. ...

time trial version of matlab compiled code using the matlab compiler
is there any way to create a time trial version of a program compiled using the matlab compiler? ...

Using library created by MATLAB compiler
Hello, I have a question on how to use library created by MATLAB compiler. After I use the mcc command to convert my m-file into C/C++ library, some files are generated. eg. .dll, .lib, .h I want to use the library in Visual C++. Is it feasible? What should I do if I want to do that? Also, what is the difference for converting the m-file to C library and that in C++ library? Thanks See the example code in <MATLABROOT>/extern/examples/compiler/matrixdriver.c and matrixdriver.cpp. That code demonstrates how to call a MATLAB Compiler generated function from a C or C++ program. To build a...

Compilation of mex files in Matlab 7
Hello, In the previous versions of Matlab (i.e. R12, R13), I usually used compiler with the following synthax: mcc -x -h -v -O all function.m to compile "function.m" into a mex file which also includes all files to which function.m refers. Question: How can I do the same in Matlab 7 ? I know that MEX files are not supported any more, and that I have to use P files (generated by PCODE). But how is it possible to automatically include all files to which "function.m" refers? Thanks. Alexander Hi Alexander, this is not possible, at least not straight forward. One possibl...

Compiling MEX-file with external library
Hello all, I am trying to compile a MEX-file, which uses an external library function. The library is available as "tcdlls.lib". But performing the compilation I get the following error. I have tried also copying the .lib file to the working directory, but this did not help. The library-file is correctly spelled. Using Visual Studio or LCC-compiler did not make any difference. What is going wrong? Thank you very much, Ralf >> mex timestwo.c -ltcdlls.lib -L"D:\Eigene Dateien\LibPath\" Warning: MEX could not find the library "tcdlls.lib" specifie...

Compile Matlab files to Mex c++
Hi everybody, I would like to optimise some parts of my program. I found some website where they said that using mcc file.m or mcc -x files.m to generate a mex file in cpp. However, when I tried this in matlab 2010, it didn't work: Unable to determine application type, since no wrapper function was specified. Please use the -W switch or specify application type via -m or -l. Type 'mcc -?' for further assistance. So, how is it possible to do this (mex files to be used in Matlab) ? Thanks you in advance ! Best regards, Duvi ...

Web resources about - Mex compilation with opencv libraries - comp.soft-sys.matlab

KDE Software Compilation - Wikipedia, the free encyclopedia
The KDE Software Compilation ( KDE SC ) is a desktop environment and an associated range of KDE Applications produced by KDE . Prior to version ...

YouTube - Tom Cruise Compilation (Run! GO GO GO GO GO!!)
Hochgeladen am 12.01.2009 A compilation of the gratuitous amount of scenes with Tom Cruise sprinting, yelling, dashing and all out running for ...

Animals in Super Bowl Ads: Video Compilation - Special: Super Bowl - AdAge
Cheetahs and horses and bears, oh my! Spots featuring fuzzy, scaly and winged creatures are a time-honored tradition in the Super Bowl. Over ...

Instagram Spotlight Compilations to Shine More Frequently
Instagram launched curated content streams called Spotlight Compilations this past Halloween, and the Facebook-owned photo- and video-sharing ...

A compilation of people hurting themselves on their new Christmas Hoverboards
Hoverboards might not be safe or legal in all places, but they’re definitely popular gifts, especially around Christmas , but controlling these ...

Emperor X, members of Porches, Sorority Noise & many more contribute songs to new Bernie Sanders benefit ...
We're just a few days away from the Iowa Caucus, the real kickoff to primary season. Bernie Sanders has been getting a lot of support from musicians, ...

Compilation Of Bunnies Yawning
Submitted by: (via The Dodo ) Tagged: bunnies , yawning , compilation , bunny , Video Share on Facebook

Compilation: Curry's record-setting 128 3-pointers
... Login Search form Search 58° Navigation Home Giants A's Sharks Warriors Kings 49ers Raiders Quakes Insiders More Tickets Shop Watch Compilation: ...

A Compilation Of Every Time R2-D2 Saved The Day
This is a compilation of every time R2-D2 saves the day in the first six Star Wars movies. He deserves a medal. Without him, pretty much everybody ...

Here's an Adorable Compilation of All the Times Leslie Jones Has Made Colin Jost Blush on Live TV
Flirting with your co-workers is usually inappropriate, but when it’s scripted on a teleprompter, what can you do except lean into it? Read ...

Resources last updated: 3/2/2016 7:42:29 PM