Matlab与C/C++混合编程调用OpenCV
好久没写博客了,今天一个师兄问到了一个关于在Matlab与C/C++混合编程时,使用OpenCV库的编译问题,所以借此机会总结成文字分享一下过程。
在使用Matlab编译包含OpenCV库的代码之前,首先假设下面的几项工作已经完成。
1)下载并解压某个版本的OpenCV至硬盘的某个目录上,并将其运行时库添加到环境变量中。

2)安装了某个版本的VC编译器,并使用Matlab的mex -setup命令,选择该版本的编译器作为默认编译器。

3)编写好包含OpenCV库的Matlab与C/C++混合编程代码。
如此一来整个编译过程便结束了,下面也顺便列一下mex相关编译选项的含义。
-Ipathname
Add pathname to the list of folders tosearch for #include files.
Do not add a space after this switch.
-lname
Link with object library. On Windowssystems, name expands to name.lib or libname.lib and on UNIX systems, tolibname.so or libname.dylib.
Do not add a space after this switch.
-Lfolder
Add folder to the list of folders to searchfor libraries specified with the -l option. On UNIX systems, you must also setthe run-time library path, as explained in Setting Run-Time Library Path.
最后也顺便提及一下,在日本有个学生也自己封装一个Matlab版本的OpenCV库,相关的资料可以在http://www.cs.stonybrook.edu/~kyamagu/mexopencv/这个地方看到。