opencv为matlab,opencv与MATLAB的关系

请问变成熟练的大家,如何把opencv编码的程序改为MATLAB中的相应语言呢,感觉看opencv编的不太理解。。。

比如:

#include

#include

#include

#include

#include

#include "segment-image.h"

int main(int argc, char **argv) {

if (argc != 6) {

fprintf(stderr, "usage: %s sigma k min input(ppm) output(ppm)\n", argv[0]);

return 1;

}

float sigma = atof(argv[1]);

float k = atof(argv[2]);

int min_size = atoi(argv[3]);

printf("loading input image.\n");

image *input = loadPPM(argv[4]);

printf("processing\n");

int num_ccs;

image *seg = segment_image(input, sigma, k, min_size, &num_ccs);

savePPM(seg, argv[5]);

printf("got %d components\n", num_ccs);

printf("done! uff...thats hard work.\n");

return 0;

}

#include引入的文件是一定需要自己写的么?

#include

#include

#include

#include

#include "image.h"

#include "misc.h"

#include "pnmfile.h"

#include "segment-image.h"

#include "filter.h"

void mexFunction( int nlhs, mxArray *plhs[], int nrhs,

const mxArray *prhs[] )

{

float sigma, k;

int min_size;

//r = mxGetPr( prhs[0] );

//g = mxGetPr( prhs[1] );

//b = mxGetPr( prhs[3] );

double *image = mxGetPr( prhs[0] );

const mwSize *dims = mxGetDimensions( prhs[0] );

sigma = mxGetScalar( prhs[1] );

k = mxGetScalar( prhs[2] );

min_size = mxGetScalar( prhs[3] );

//mexPrintf( "sigma: %.3f, k: %.3f, min_size: %d\n", sigma, k, min_size );

int height = dims[0];

int width = dims[1];

int c = dims[2];

typedef unsigned char uchar;

imageRGB *input = new imageRGB(width, height);

for (int y = 0; y < height; y++)

{

for (int x = 0; x < width; x++)

{

int index = height*x + y;

imRef(input, x, y).r = static_cast( image[index] );

imRef(input, x, y).g = static_cast( image[width*height + index] );

imRef(input, x, y).b = static_cast( image[width*height*2 + index] );

}

}

int num_ccs;

imageRGB *seg = segment_image(input, sigma, k, min_size, &num_ccs);

mexPrintf( "number of regions: %d\n", num_ccs );

plhs[0] = mxCreateNumericArray( 3, dims, mxUINT8_CLASS, mxREAL );

uchar *output = static_cast( mxGetData(plhs[0]) );

for (int y = 0; y < height; y++)

{

for (int x = 0; x < width; x++)

{

int index = height*x + y;

output[index] = imRef(seg, x, y).r;

output[width*height + index] = imRef(seg, x, y).g;

output[2*width*height + index] = imRef(seg, x, y).b;

}

}

delete input;

delete seg;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值