我做的是MATLAB与vs混合编程,出现现在的问题不知道是哪的问题,请大神指教。我想看一下调用完MATLAB中的程序后生成的数据是否正确代码如下:
#include "stdafx.h"
#include"cv.h"
#include"highgui.h"
#include
#include "lvbo.h"
#include "CvvImage.h"
using namespace std;
int main()
{
IplImage* image = cvLoadImage( "H:\lena.bmp", 0 );
mwArray mwdisp(image->height,image->width,mxUINT8_CLASS);
IplImage* pTemp = cvCreateImage(cvSize(image->height, image->width), IPL_DEPTH_8U, 1); //n*m创建图像
cvTranspose(image, pTemp);//m*n->n*m,复制image中的数据到ptemp中
CvMat* pMat = cvCreateMat(image->height, image->width, CV_8UC1);//pmat:n*m分配矩阵空间
cvConvert(image, pMat);//pmat:n*m,将图像转化为矩阵,任意类型数据的矩阵
mwdisp.SetData(pMat->data.ptr, pMat->height*pMat->width);
mwArray ImageData(image->height,image->width ,mxDOUBLE_CLASS);
shiyan1(1,ImageData,mwdisp);
double *yData=(double *)malloc(image->height*image->width);
if(yData==NULL)
{
printf("failed to allocate memory for y");
return 0;
}
ImageData.GetData(yData, image->height*image->width);
int width=image->width;//图片宽度
int height = image->height;//图片高度
for (size_t row=0;row<height;row++)
{
//uchar* ptr = (uchar*)pMatL0->data.db+row*image->width;//获得灰度值数据指针
for (size_t cols=0;cols<width;cols++)
{
int intensity=yData[row*image->width+cols];
cout<<intensity<<" ";
}
}
free(yData);
getchar();
return 0;
}