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 206947 articles. 560 followers. lunamoonmoon (258) is leader. Post Follow

1 Replies
687 Views

Similar Articles

[PageSpeed] 11
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:

Problem with the compiler?
Hi NG I've written this little test-program. Why does it open a console/cmd shell and how to prevent this? Is it a problem with my compiler (Dev-C++ 4.9.8.0 from Source-Forge)? -------------CODE-------------- #include <windows.h> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { while (true){ // do nothing } return 0; } ------------------------------- "Jan Kassens" <Jan_Kassens@web.de> wrote in message news:c7e045$hne$07$1@news.t-online.com... > Hi NG > I've written this little test-program. Why does ...

uri.scm
I'm trying to release some of the mostly-finished Scheme libraries I've been using. The first of these is my current Web URI library, "uri.scm": http://www.neilvandyke.org/uri-scm/ Comments appreciated. | *Note: This version of the library has endured some testing, and is | being used in at least one production application, but be advised that | some design refinements and API changes are expected. Especially, we | are reconsidering the use of immutable strings and pairs, would like | to add more of the extensibility of [UriFrame], and need to look at | the forthcom...

c mex
Hi, Here is a sample code illustrating my problem. ------------------------------------------------------ char myCharVal; int myIntegerVal; plhs[0] = mxCreateDoubleScalar(myIntegerVal); plhs[1] = mxCreateString(myCharVal); ------------------------------------------------------- I'd like to pass the character myCharVal to the output parameter of the mex function (plhs). For Strings I'm using the function mxCreateString. The function mxCreateString is not working for single characters. It requests a 'pointer to const char' as input data type. Is th...

path for include in mex-file
Hi, I have got the following question: My Fortran subroutine contains an "INCLUDE". How do I set the path? If I use this command mex -I N:\Datos\APD\FM\Aerodata Aerodata_check_mex.f I get an error message. What=B4s the problem? Thanks for your help, Oliver Hi Oliver, remove the space: -IN:\Datos\APD\FM\Aerodata Titus "Oliver Trujillo" <o.trujillo@gmx.de> schrieb im Newsbeitrag news:1172761058.121508.184940@30g2000cwc.googlegroups.com... Hi, I have got the following question: My Fortran subroutine contains an "INCLUDE". How do I set the path? If ...

Mex lock issue...
So I accidentally ran a file that called MexLock(), but not MexUnlock(). Now I get the following error when I try to compile the code: Your MEX-file is locked and must be unlocked before recompiling. How do I unlock the MEX-file from the command line? clear all and clear mex do not work. Thanks! ...

Compiling Fortran into MEX
I am using matlab ver 7.1 under Windows XP. I would like to create a mex file for some legacy Fortran code. I reviewed the creating mex under matlab help. I attempted to follow the example provided by compiling the example Fortran code using mex -setup and selecting the Digital Fortran 6.0. The following errors were generated, please provide any help in understanding the errors and possible solutions. >> mex yprimef.f yprimefg.f Command line warning D2009: unrecognized flag /fpp:/m /SC:\Program Files\MATLAB71/extern/include ignored. yprimefg.f yprimefg.f(1): error FOR2173: column 6 non-...

Hugo compilation errors
Hi all, I'm trying to compile Hugo 3.1.0 from source on Debian/testing GNU/Linux and am getting compiler errors despite the fact that I'm fairly certain that all the requisite libraries are installed. The errors themselves are wxwindows related, but I'm wondering if it could be the Makefile. The errors are: $ make cd hewx && make make[1]: Entering directory `/home/p/tmp2/hugov3.1.0/hewx' g++ -c hewx.cpp -I- -I. -I../source -I/usr/local/include -I/usr/include/g++-3 - D__WXGTK__ -DWXWINDOWS -DNO_WXCARET -fwritable-strings -O2 -Wall `wx-config --cf l...

Compiler flags
Can someone point me to a website that lists the compiler flags for the Linux c++ compiler. Yes, I know it's called c++ but I am using it to compile .c files. spasmous wrote: > Can someone point me to a website that lists the compiler flags for the > Linux c++ compiler. Yes, I know it's called c++ but I am using it to > compile .c files. There's a chap called Google who can be contacted at http://www.google.com - he knows all about that sort of thing. J. J. Farrell said: > > spasmous wrote: >> Can someone point me to a website that lists the compiler fl...

compiling from the svn repository
Ok, so this might be a stupid question, but I just got the latest ruby from the cvs repo and I can't find 'configure' in there ? So how am I suppose to compile ? I am puzzled... Note that I got the src from cvs using: $ cvs -d :pserver:anonymous@cvs.ruby-lang.org:/src login $ cvs -z4 -d :pserver:anonymous@cvs.ruby-lang.org:/src co ruby (I am following the instruction given on the ruby home page, when you click on 'cvs repositories') Now, how exactly am I suppose to compile now (usually a simple './configure; make; make install' works fine...), but 'configure&#...

"mex -g" throws "Error while obtaining sizes from MEX S-function"
hi! I programed an c++ s-function for simulink - this function nearly works fine... now I wanted to build a debug-mex s-function with "mex -g blahblah.cpp". it builds just fine, but if I run the simulation, simulink always throws an error: "Error while obtaining sizes from MEX S-function" but this only happens if I use the "-g" switch... btw. is there any other way than calling "int 3h" for debugging? because when linking in MS-VS 2005 matlab doesn't like my mexw32 s-function... thanks in advance! sincerely thilo ...

The Microsoft libraries needed to create mexw32 cross platform mex functions is missing. There was a library under 2008b.
The Microsoft libraries needed to create mexw32 cross platform mex functions is missing. There was a library under 2008b. I am (or at least want to) using Microsoft's VC++ 2008 express to create both mexw64 and mexw32 functions for the respective 32 (x86) or 64 (x64) bit platforms and respective versions of matlab. My operating system is XP64, and the matlab version I am using is a x64 version of R2009a. I need to create mexw32 for other members of my work group that have not been upgraded to x64 machines yet. I do realize I can't run a mexw62 on my x64 machine. When I try to compi...

MEX again...
OK, my last posting to Steve re: not finding CVF made me go try yet _one_more_time_ (tm). Voila!!! Reading the mexsetup.pm file got me to look at the installed/supplied .stp files and found a typo in the cf61opts.stp file. So fixed up a copy of if modified for CVF 6.6 as installed and then mex -setup seemed to run successfully. So, tried the "timestwo" demo as being about as simple as they come. Seemed to compile but failed on linking and I'm unable to ascertain why. Here's the output of mex w/ the verbose option...anybody have any ideas on how to determi...

smart compiler vs luser, part II.
Hi. I need help. I just finished simple ''parser''. It can split csv strings: (let ((example "a,b,c,\"d,e,f,\"g,h")) (map nil (lambda (c) (princ c) (terpri)) (split-csv-string example))) output: a b c "d,e,f,"g h NIL Unfortunately I got warning (cmucl 19a): ; In: DEFUN SPLIT-CSV-STRING ; (COND (# #) (# #) (# :NORMAL) (# :QUOTED)) ; --> IF COND IF COND IF COND IF ; ==> ; (COND) ; Warning: A possible binding of STATE is not a (VALUES &OPTIONAL KEYWORD &REST T): ; NIL ; ; Compiling Top-Level Form: ; Com...

how to count lines of compiled code in C++ executable/library?
Hello All, Can please someone suggest how to count lines of compiled code in C++ executable/library? Thanks, Alona allab@sympatico.ca wrote: > Can please someone suggest how to count lines of compiled code in C++ > executable/library? A simple 'wc -l' might already do what you want, otherwise I suggest putting more relevant info about what you want into your question. Uli -- http://www.erlenstar.demon.co.uk/unix/ Uli, 'wc -l ' should be run on an output of another command. What command should be used to read the content of teh executable file? Thanks, Alona ...

Compiling woes Solaris 10
Hi - I've been out of the *nix world for a while so I really feel like a newbie again. I'm trying to get back into developing software and thought I would start by compiling all the gnome components. It has been a "treat." I've learned a lot but now I am trying to compile libgtop-2.10.1 and I've found a nut I can't crack. The programs want to include sys/msg.h and do sizeof(struct msginfo). Same situation with shm.h and sizeof(struct shminfo). I have googled and found that msginfo is supposed to be defined in /usr/include/sys/msg.h -- but it isn'...

C-Mex File R13 and up Compatibility
I've written this mex file in Visual Studio .NET 2003 using the R13 version I have installed. However, when I pass the dll file off to my friend with R2006a (I can't quite afford that) he tells me that he gets this error: ??? Invalid MEX-file 'C:\Documents and Settings\BigG\Desktop\NuCam Matlab Driver\NuDispatcher.dll': The specified module could not be found. I'm not sure what could possibly be wrong. I read somewhere on this group that M-Mex files are incompatible between versions, but no mention of C-Mex files. But if they are incompatible between versions, does this ...

_beginthread() does NOT compile ??
What is wrong? What am I missing? I'm trying to start a thread like shown in MS's sample program for demonstrating the function _beginthread() called BEGTHRD the function I'm calling is different having no input argument void Card(void) { ...stuff... } the line _beginthread(Card, 0, NULL); results in this error: error C2664 '_beginthread' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void *)' If I "dummy" up the function 'Card' to more closely match the sample program where 'Card...

MEX MCC
I have a relatively simple Matlab function containing several nested loops that cannot be avoided with vectorization. Although efforts have been made to speed up the function's execution (e.g. searching via columns as opposed to rows, matrix initialization, etc.), its execution speed remains slow. Does is make sense to convert a .m function to a C equivalent in an automated fashion using the mcc compiler and then convert the resulting C function to a .mex? Will this increase execution speed? How would I go about doing this? ...

Using OpenMPI via Mex file
Hello Newsgroup Users, I have a question related to OpenMPI with Matlab, using Matlab v.7.10 and OpenMPI v.1.4.3 on Ubuntu v.11.0.4. I wrote a wrapper C function, in which it calls the MPI interface as the following: MPI_agent.c ================================================================= void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[] ) { char arg1[65]; mxGetString(prhs[0], arg1, sizeof(arg1)-1); if (!strcmp(arg1, "MPI_Init")) { MPI_Init(0,0); } else if (!strcmp(arg1, "MPI_Finalize")) { M...

Suppress mex output
Is there a way to have matlab suppress output from a mex file. For example, if I write a file called hello.mex and inside I have fprinf('Hello World') then compile the mex file and go into matlab and call the mex file >> hello; 'Hello World' This might not be possible, since 'Hello World' is not being returned to matlab, its just being output inside the mex file. Thanks! Ping. Any progress on this question in the last 5 years? Kevin <none@none.none> wrote in message <ef3766d.-1@webx.raydaftYaTP>... > Is there a way to have matlab suppress outp...

Matlab x64 not recognizing compilers
I am trying to create some .dll using the mex command on 64 bit matlab on a 64 bit machine and it continues to say that ther eare no compilers installed on the machine. I have the license for the matlab compilers and they are installed I have visual studio 8 installed Thanks for your help ...

Watcom not showing up on mex compiler list
Hello Why can't MATLAB find all my compilers? If I do a "mex -setup" and ask it to search for my installed compilers, it finds: ---------------- Select a compiler: [1] Lcc C version 2.4.1 in C:\MATLAB\sys\lcc [2] Microsoft Visual C/C++ version 8.0 in C:\Visual [0] None ---------------- Odd thing is, I have WATCOM as well, which is installed in C:/WATCOM. Is there any way to force MATLAB to find this? Okay, I've found that Watcom may not properly install itself :( "Unable to open ide.cfg" is what I get, when running the IDE, which then proceeds to open, b...

compiling issue
Is there a simiple way to&nbsp;reference(compile) without manually collecting subVIs in one directory? If I try to open a main VI project from another PC, LV tries to look for all the subVIs that are not in the same location/paths. &nbsp; It seems that it will take a lot of effort to individually find and gather up all the subVIs. &nbsp; &nbsp; For LabVIEW 7.1 and earlier, the easiest way is to save the application into a library (.llb) file. This will collect all the VIs used into a single file that can be easily moved to another machine. From the File menu, select Save Wit...

Unable to compile kernel
Hi, I am not an expert for linux, but I want to compile (recompile...) the kernel or modules, whatever. I'm in the correct directory, I type 'make menuconfig', choose some points in the menu, save it to disk and then try to compile the modules, but I get errror messages. Here is the output: [root@localhost 2.6.11-1.1369_FC4-i686]# make modules modules_install CHK include/linux/version.h CHK include/asm-i386/asm_offsets.h make[1]: *** No rule to make target `init/main.o', needed by `init/built-in.o'. Stop. make: *** [init] Error 2 How can I find out what is...

Installation Question for libxml & Borland C++ 5 Compiler
Hello, I have tried many avenues (web search, borland website, libxml website) before deciding to post here. I'm trying to install libxml2 on windows ME to work with my Borland C++ 5 Compiler (command line). Read through the installation guides from xmlsoft.org. Downloaded libxml2, libinconv-1.9.1 and zlib. Followed the instructions for the zlib installation. However, it seems that libinconv can only be compiled using Microsoft Visual C++. Is there an alternative method for a Borland C++ 5 (command line) user like me? Using the example, tree1.c from xmlsoft and compiling like this, ...