Matlab调用OpenCV(C++)程序

本文详细介绍了如何在Matlab环境中调用依赖OpenCV的C++程序,以实现论文《Rolling Guidance Filter》中的算法。通过编写接口函数,数据在Matlab与C++间传递,确保程序在保持C++效率的同时,能被Matlab便捷运行。教程中提到,OpenCV库需正确配置,并在编译时加入相应选项。
摘要由CSDN通过智能技术生成

本文以论文"Zhang Q, Shen X, Xu L, et al. Rolling guidance filter[C]//European Conference on Computer Vision. Springer International Publishing, 2014: 815-830."提供的C++程序为例(依赖OpenCV),编写matlab调用OpenCV程序,使其可以用matlab运行,而且保持C++程序的快速性。

其中参考了博文matlab调用C程序  Matlab与C++混合编程(依赖OpenCV)。但是这两篇博文有些地方讲的不是很清楚,在接口函数中需要将数据首先从matlab读入进C++,然后经过C++函数运行有输出后,再将输出读出给matlab,这个过程是最重要的。

首先我把OpenCV放在了F盘,每次修改完.cpp文件后,都要使用matlab编译修改才可以生效,如果没有OpenCV的话,直接运行mex mexRollingGuidanceFilter.cpp就可以,但是有OpenCV后还需要加上它才可以,具体如下(具体的关于OpenCV与Visual Stdio的初始化连接就不介绍)

mex mexRollingGuidanceFilter.cpp -IF:\opencv\build\include -LF:\opencv\build\x64\vc10\lib -lopencv_core249 -lopencv_imgproc249 -lopencv_highgui249
然后是编写matlab调用主体函数,接口程序中调用的数据就来自这个函数,这个函数的名称没有特别要求,但是函数内部调用的C++函数名称必须和.cpp名称相同,具体如下

% /***************************************************************/
% /* Function: filter
% 	* 
% 	* Description: rolling guidance filter core code by using bilateral filter.
% 	* 
% 	* input arguments:
% 	*  img: input image. Accept CV_8U and CV_32F type. Accept any number of channels.
% 	*  sigma_s: spatial sigma (default 3.0). Controlling the spatial weight of bilateral filter and also the filtering scale of rolling guidance filter.
% 	*  sigma_r: range sigma (default 0.1). Controlling the range weight of bilateral filter.
% 	*  iteration: the iteration number of rolling guidance (default 4).
% 	*    
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值