读书人

Windows停Matlab使用G++ DLL实现图像处

发布时间: 2013-10-06 18:25:14 作者: rapoo

Windows下Matlab使用G++ DLL实现图像处理

由于Matlab配置G++编译器没有成功(win8+TDM-mingw64),所以尝试用G++编写动态链接库实现图像处理

环境:

OS: win7和win8

C++: tdm-mingw64

Matlab 2013

方法如下:

1 编写库头文件matlab_imgp.h

#ifndef MATLAB_IMGP

#define MATLAB_IMGP

#ifdef __cplusplus

extern"C"

{

#endif

__declspec(dllexport) void imagep(double *img,int dims[3]);

#ifdef __cplusplus

}

#endif

#endif

2 编写matlab_imgp.cpp

#include "matlab_imgp.h"

void imgp(double *img,int H,int W,int C,int radius,double Alpha)

{

img[0] = 5;

}

3 编写matlab编译脚本build_run.m

%unloadlibrary('matlab_imgp');

system('g++ -std=c++0x -shared matlab_imgp.cpp -o matlab_imgp.dll');

loadlibrary('matlab_imgp.dll','matlab_imgp.h');

libfunctions matlab_imgp-full

% p = libpointer('doublePtr', zeros(1,10)); % initialize array of 10 elements

% get(p)

% calllib('matlab_imgp', 'imagep', p, [1, 10, 0]);

% get(p)

img = double(imread('rice.png'));

[h w c] = size(img);

tic;

%img作为参数,对其的修改自动作为返回值

x = calllib('matlab_imgp','imgp', img, h, w, c, 2, 0.1);

toc

unloadlibrary('matlab_imgp');

缺点:

此种运行方式,运行效率比.mex编译方式慢得多

读书人网 >图形图像

热点推荐