Mex compilation with opencv libraries

  • Permalink
  • submit to reddit
  • Email
  • Follow


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
Reply Fin 1/20/2010 11:03:05 PM

See related articles to this posting


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
Reply mystic.satvik (1) 6/3/2011 6:47:04 PM
comp.soft-sys.matlab 203718 articles. 537 followers. Post

1 Replies
637 Views

Similar Articles

[PageSpeed] 27


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

library file not being recognized during mex compile
I had previously been able to compile my mex file using the command in Matlab: >> mex CMEXsfcn_code.c MyLibrary.lib Somewhere along the line, I started having problems with this compile process, and now when I execute the above command, the .lib file (the same version of which is still contained in my working directory) is now not recognized, and I get a string of error messages relating to functions contained in the .lib file that are used in the .c file. Does anyone have any ideas about why, even though I'm still working in the same directory and using the same files, the conte...

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 mex-funtions with C using OpenCV
I am using C functions which in turn uses OpenCV. I need to compile these functions in matlab and I think it is necessary to create mex functions. As I compile these functions? Would appreciate urgent help. Thanks Helder <Refega@ymail.com> wrote in message <1843030343.24900.1291071776440.JavaMail.root@gallium.mathforum.org>... > I am using C functions which in turn uses OpenCV. I need to compile these functions in matlab and I think it is necessary to create mex functions. As I compile these functions? > Would appreciate urgent help. > Thanks As you mentionned yo...

Compile C source code to a library with MEX
Is there any way to do this? I want to create a *.lib from my C source code for use in other S-Functions. Thanks in advance, Ashish. ...

MEX library compiled in MaC throws exception
Hi Everyone, I am trying to compile a set of C files to create MEX dynamic library. I have done it successfully for Windows 32 bit & 64 bit. Now I am trying to do the same on a MaC. Every piece of code used for the windows is the same besides having changed a few libraries e.g. while doing it on windows I used the vcf2c.lib to compile fortran to c generated code and in the MaC I am using the f2c.lib. The .mexw32 library file generated on the Windows allows flawless execution of the .M files . In the MaC OS-X though the .mexaci file is created compiling the same piece of code when i trying...

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...

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...

build a static library instead of a dynamic one with MEX compiler
Hello I m looking for an option of the mex compiler in order to produce a static mex file with all the code, that it needs, already inside it. which can substitute all the external references inside my c code with the real code from the external library. i tried to do that because I created a mex file to put inside a 2ndlevel sfunction block mex file.c -l APP_Numerical and until now everything is fine the program works on Simulink (the option -l is there, because I made some references to an external library) Then in order to use it in a real time simulator, I need to tra...

mex fortran 77 compiler link static library problem
Hi all, I have a fortran program that I originally wrote on windows using f90 (Compaq visual fortran). I have slightly modified to port it in fortran 77 to be compiled on a Linux 64-bit machine. I have another static library that I wrote in fortran 90, and was successfully compiled on Linus using "ifort". When I try to mex the fortran 77 code (using g77; since ifort is not availble from matlab mex), I used: mex -O -output test testing.f mylibrary.lib where mylibrary.lib is located in the same directory. The compilation finished successfully, however when I run it, it says: ??? In...

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 ...

Compiling mex function with link to external library
Hello, I'm trying to compile a mex function that links to an external library. It is failing, being unable to find the "symbols" to the library function calls. I've spent an embarrassing amount of time trying to figure this out and any help would be greatly appreciated. Here's what I've got: ---------- >> mex('gsf_Read.c','.\gsf_0303\WinGSF\Debug\WinGSF_lib.lib') Creating library C:\Users\vschmidt\AppData\Local\Temp\mex_p5d3gD\templib.x and object C:\Users\vschmidt\AppData\Local\Temp\mex_p5d3gD\templib.exp gsf_Read.obj : error LNK2019:...

Can you use MFC functions/libraries with s-functions and MEX compiler?
Hi there, Essentially what I have is the source code for an MFC application that interacts with some external hardware. I want to use this hardware through MATLAB and am currently trying to implement the C++ source code into S-functions using the MEX compiler. However, I've been having numerous problems compiling and linking, especially with afxwin.h and other headers. The way i see around this is to go through the existing code bit by bit and pick out the functions and classes which make calls to the MFC C++ Library and remove them. However, from numerous searches through forums, et...

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...

How to compile mex function using mcc compiler
I am using mcc compiler to compile a matlab function myfun.m into c code. The myfun.m calls a mex function digamma.c, but I do not know the correct way to deal with this mex function. when I tried mcc -m -v myfunction. The compiling was finished where, but when I run this executable, there is error information like: ??? Undefined function or method 'digamma' for input arguments of type 'double'. Error in ==> rtmCGS at 151 I noticed that digamma.c used #include "util.h", which is not a default head file. Is this the reason? I really need help about this. Thank...

making mex-file compilation dependant on the compiler
I want to have a script compile my mex file using different options depending on what compiler is set up. Passing switches seems more flexible than editing mexopts.bat and having several versions. This seems to work just fine from the command-prompt, but when I make a script/function that does the same, I get a strange error. cc = mex.getCompilerConfigurations if strcmp(cc.Details.CompilerExecutable, 'icl')% using Intel compiler mex -v OPTIMFLAGS="$OPTIMFLAGS /O3 /DNDEBUG" hello.c else mex hello.c end ??? Error: File: buildmex.m Line: 3 Column: 5 "mex" was pre...

Compile a Program with mex.h without mex
Hello I'm writing a C program that can be called from matlab as well as from a console. That means, I have a main(...) as well as a mexFunction(...). I have no problems when compiling with mex, but I get linker errors when I try to compile it with another C compiler like gcc. This of course happens, because some libs are missing. But which libs does the compiler need to succeed? I tried several folders in the MATLAB/extern area, but had again linker errors. Is it possible at all to compile a file containing calls to mex.h without mex? Notice: Functions of mex.h are only called from mexF...

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...

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 c code but libraries are compiled in c++
hi, We have written cunit code for testing some APIs. defination of those APIs are in c++ and .so library is created of them. when I compile my cunit code it gets compiled successfully but while liking it gives undefined reference to symbol. can anyone help me in this matter. Regards Sumit Shrivastava On 29 May 2007 04:11:14 -0700 sumit <sumit.shrivastava09@gmail.com> wrote: | We have written cunit code for testing some APIs. defination of | those APIs are in c++ and .so library is created of them. when I | compile my cunit code it gets compiled successf...

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...

Older gcc using a library compiled with a different compiler?
I have an application that has me forced to use gcc 2.95.3 on solaris/ SPARC. I am wondering, is there any problem with and older gcc like this using a library that was compiled with gcc 3.4? What if I get a version of this library compiled with sun pro? Is it an issue then if I use this old gcc and attempt to call functions in this library? Thanks much, mohan Mohan Khurana <mohankhurana@gmail.com> writes: > I have an application that has me forced to use gcc 2.95.3 on solaris/ > SPARC. How can an application force you to do anything? Did it put a gun to your head? Now, if...

link a c compiled application with a c++ compiled library ?
Hi, I've searched nearly one hour for this but found nothing usefull :-/ So my question is simple : Is it possible to link a c compiled application with a C++ compiled library ?? If yes, how would it possible.. (I guess this would be indirectly posible by using some wrapper around the c++ library, but I'm aboslutely not wanting to do that in my case, well at least if I have to write that wrapper manually myself). I looked at gcc,g++ man pages, gcc online documentation, .. but can't even find a beginning of info related to that :-/ Thank you if you can help me. Regards, ...

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...