u014650053
妮儿1
2015-04-12 07:26

mfc+MATLAB+opencv出现内存泄露问题

  • c

我的程序这么多的内存泄露,但是不知道具体是哪的原因,我想做的是vs与MATLAB混合编程实现图像处理。
Detected memory leaks!
Dumping objects ->
{301} normal block at 0x007DC1F8, 47 bytes long.
Data: 4A 50 45 47 2D 32 30 30 30 20 43 6F 64 65 20 53
这是vc++程序
void CMFCApplication17Dlg::OnClickedButton5()
{
{
// TODO: Add your control notification handler code here
//CFileDialog fDlg(TRUE,"bmp","*.bmp",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
//"原始图像(*.bmp)|*.bmp|所有文件(*.*)|*.*||",NULL);
//if (fDlg.DoModal() == TRUE)
//{
//Open_Filename = fDlg.GetFileName();
IplImage *image=NULL;
if(image)
cvReleaseImage(&image);
image = cvLoadImage("H:\lena.bmp",1);
if (image==0)
MessageBox("Reading Failed");
else
DrawPicToHDC(image, IDC_showimage);
cvReleaseImage(&image);
}
}

//}

void CMFCApplication17Dlg::DrawPicToHDC(IplImage img, UINT ID)
{
CDC *pDC = GetDlgItem(ID)->GetDC();
HDC hDC= pDC->GetSafeHdc();
CRect rect;
CWnd * pWnd;
pWnd=GetDlgItem(ID);
pWnd->SetWindowPos( NULL,0,0,img->width,img->height,SWP_NOZORDER | SWP_NOMOVE );
pWnd->GetClientRect(&rect);
CvvImage cimg;
cimg.CopyOf(img);
cimg.DrawToHDC(hDC,&rect);
ReleaseDC(pDC);
}
void CMFCApplication17Dlg::OnClickedButton1()
{
if( !lvboInitialize())

{

printf("Could not initialize !");

return ;

}
_CrtDumpMemoryLeaks();
IplImage *image=NULL;
if(image)
cvReleaseImage(&image);
image = cvLoadImage("H:\lena.bmp",1);
if (image==0)
MessageBox("Reading Failed");
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(pTemp, pMat);//pmat:n*m,将图像转化为矩阵,任意类型数据的矩阵

    mwdisp.SetData(pMat->data.ptr, pMat->height*pMat->width);
    cvReleaseMat(&pMat);
mwArray ImageData(image->height,image->width ,mxDOUBLE_CLASS);  
cvReleaseImage( &pTemp );

shiyan2(1,ImageData,mwdisp);

IplImage* pTempL0 = cvCreateImage(cvSize(image->height, image->width), IPL_DEPTH_64F, 1); //n*m
CvMat* pMatL0 = cvCreateMat(pTempL0->height, pTempL0->width, CV_64FC1);//n*m

    ImageData.GetData(pMatL0->data.db,pMatL0->height*pMatL0->width);         
    cvConvert(pMatL0,pTempL0);//mat->iplimage   
    cvReleaseMat(&pMatL0);
    IplImage* pL0SmoothImg =cvCreateImage(CvSize(cvGetSize(image)),IPL_DEPTH_64F,1);//m*n
    cvTranspose(pTempL0, pL0SmoothImg); //n*m->m*n
    cvReleaseImage( &pTempL0 );
    IplImage* result =cvCreateImage(CvSize(cvGetSize(image)),IPL_DEPTH_8U,1);
    cvReleaseImage( &image );
      double minVal;

double maxVal;
cvMinMaxLoc(pL0SmoothImg, &minVal, &maxVal);
printf("%f ",minVal);
printf("%f",maxVal);
// Normalize image (0 - 255) to be observed as an u8 image
double scale = 255/(maxVal - minVal);
double shift = -minVal * scale;
cvConvertScale(pL0SmoothImg,result,scale,shift);//
cvNamedWindow("去噪后图像",CV_WINDOW_AUTOSIZE);
cvShowImage("去噪后图像",image);
cvWaitKey(0);
DrawPicToHDC(image, IDC_showimage2);

//cvReleaseMat(&pMat);

cvReleaseImage( &pL0SmoothImg);
cvReleaseImage( &result );
lvboTerminate();
}
下面是配置生成的MATLAB程序
function h=lvboshibie(a)
%a=imread('lena.bmp');
%figure;imshow(a);
%title('原图像');
a=im2double(a);%将数变为double型数
d=100.*a;%求出估计的灰度时用数据
b=imnoise(a,'gaussian',0.015);
C=im2double(b);
b=im2col(C,[3,3],'distinct');%将加躁图像分割成3*3的小窗口
[i,j]=size(b);
m=zeros(i,j);
n=size(i,j);

for i=1:9
for j=1:5180
m(i,j)=b(i,j)-b(5,j);%用3*3的窗口中的中心值对窗口中的数据求出估计的受躁程度
m(5,j)=0.001;
n(i,j)=m(i,j)./b(5,j);
end
end
%为用accumarray函数把数据变回原来的排列方式做准备
%制造c矩阵
K=[1 1 0;1 2 0;1 3 0;2 1 0;2 2 0;2 3 0;3 1 0;3 2 0;3 3 0];
A=K;
for ii=1:5179;
A=[A;K];
end
g=zeros(1,5180);
b=[1:5180];
b=[g,g,b];
b=[b;b;b;b;b;b;b;b;b];
b=reshape(b,[46620,3]);
c=A+b;
val=reshape(n,[46620,1]);
A=accumarray(c,val);%使用此函数把原来用im2col变成9*5180的矩阵变为一个个3*3的小矩阵
D=reshape(A,[3,15540]);
%将矩阵变为原来的222*210的形式
M = [];
B=[];
for i = 1:3:15538
temp=D(:,i:i+2);

M = [M; temp]; % 使矩阵变为15540*3
end
for j=1:222:15539

TEMP=M(j:j+221,:);
B = [B, TEMP]; % 使矩阵变为220*210
end
%使矩阵为222*208
B=B(1:222,1:208);
E=B+100;
r=d./E;
e=im2uint8(r);
f=im2uint8(a);
[m,n]=size(e);
for i=1:m
for j=1:n
if (e(i,j)>=0)&&(e(i,j)<=50)
u=23;
q=23/3;
v(i,j)=e(i,j)-u;
V(1)=2*q^2;
elseif (e(i,j)>=51)&&(e(i,j)<=100)
u=83;
q=47/3;
v(i,j)=e(i,j)-u;
V(2)=2*q^2;
else
u=117;
q=138/3;
v(i,j)=e(i,j)-u;
V(3)=2*q^2;
end
end
end
v=im2double(v);
Q=v.^2;
for i=1:m
for j=1:n
if (e(i,j)>=0)&&(e(i,j)<=50)
H(i,j)=im2double(Q(i,j)/V(1));
N(i,j)=exp(-H(i,j));
elseif (e(i,j)>=51)&&(e(i,j)<=100)
H(i,j)=im2double(Q(i,j)/V(2));
N(i,j)=exp(-H(i,j));
else
H(i,j)=im2double(Q(i,j)/V(3));
N(i,j)=exp(-H(i,j));
end
end
end
s=ones(224,210);
l=s*26;
l(2:223,2:209)=e;
o=zeros(224,210);
o(2:223,2:209)=N;
[m,n]=find(l<=25);
q=size(m);
for i=1:q
x(m(i),n(i))=l(m(i)-1,n(i)-1)*o(m(i)-1,n(i)-1)+l(m(i)-1,n(i))*o(m(i)-1,n(i))+l(m(i)-1,n(i)+1)*o(m(i)-1,n(i)+1)+l(m(i),n(i)-1)*o(m(i),n(i)-1)+l(m(i),n(i))*o(m(i),n(i))+l(m(i),n(i)+1)*o(m(i),n(i)+1)+l(m(i)+1,n(i)-1)*o(m(i),n(i)-1)+l(m(i)+1,n(i))*o(m(i)+1,n(i))+l(m(i)+1,n(i)+1)*o(m(i)+1,n(i)+1);
y(m(i),n(i))=o(m(i)+1,n(i))+o(m(i),n(i))+o(m(i)-1,n(i))+o(m(i)+1,n(i)-1)+o(m(i)-1,n(i)-1)+o(m(i),n(i)-1)+o(m(i)-1,n(i)+1)+o(m(i),n(i)+1)+o(m(i)+1,n(i)+1);
l(m(i),n(i))=x(m(i),n(i))/y(m(i),n(i));
end
h=l(2:223,2:209);
h=round(h);
%figure,imshow(h,[]);
%title('第二次去噪效果');
end
不知道到底是哪的问题,还请大家帮帮忙,先谢谢了。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换