Windows下Matlab使用G++ DLL实现图像处理
2013-10-05 10:14
591 查看
由于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编译方式慢得多
环境:
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编译方式慢得多
相关文章推荐
- 数字图像处理及matlab实现知识点总结1-4
- 使用双线性插值法放大图像(matlab实现)
- 使用QT实现一个图像处理软件1 —— 图片的加载和显示
- 数字图像处理,经典滤波算法去噪对比实验(Matlab实现)
- 深度学习FPGA实现基础知识15(Matlab图像处理“卷积”运算)
- [数字图像处理]常见噪声的分类与Matlab实现
- matlab的gui图像处理操作界面,实现重置和退出按钮功能
- 使用Halcon实现图像处理
- 使用OpenCV 实现多摄像头图像处理笔记(1):DirectShow的配置过程可能出现的问题
- 数字图像处理,小波变换一维Mallat算法的C++实现(matlab验证)
- 数字图像处理]常见噪声的分类与Matlab实现
- matlab实现分水岭算法处理图像分割
- 使用MATLAB对图像处理的几种方法(下)
- 图像处理中使用多线程及图像分块实现加速运算
- Matlab中图像处理实例:灰度变换,空域滤波,频域滤波,傅里叶变换的实现
- MATLAB图像处理_plot的使用详解
- Android Studio使用Opencv实现图像的实时处理
- 使用Matlab进行图像处理
- 使用谷歌开源组件tesseract-OCR识别身份证,通过opencv处理图像后再进行识别(windows版本)
- 图像处理学习笔记之MATLAB中imhist、imadjust、stretchlim函数实现