【发布时间】:2015-01-12 01:09:12
【问题描述】:
我正在尝试寻找一种方法来避免在 while 循环内使用 cvCreateImage,因为我已经意识到这会导致 内存泄漏。
我想要this 之类的东西 - 尽管没有内存泄漏。
我不知道为什么这段代码不起作用。
下面的代码是我认为可以工作的,但是运行时会中断。
if((capture = cvCreateCameraCapture(0)) == NULL) {
printf("connect cam first\n");
return -1;
}
IplImage *detecImg = cvCreateImage( cvSize(WIDTH, HEIGHT), 8, 1 );
IplImage *frameImage = NULL;
IplImage *notImage = NULL;
while(1){
cvWaitKey(1);
cvSplit(frameImage, a, b, c, NULL);
//detect objec from a,b,c.....output is "detecImg"
cvSetImageROI(detectImg, Roi); //Roi is changing depends on detection result
notImage=cvCloneImage(detectImg);//cvCloneImage,cvCopy not working...
cvNot(notImage, notImage);
copyNotImg = cvCloneImage(notImage);
... continues ...
}
如果我使用下面的这段代码,它可以正常工作,但会泄漏一点内存。
if((capture = cvCreateCameraCapture(0)) == NULL) {
printf("connect cam first\n");
return -1;
}
IplImage *detecImg = cvCreateImage(cvSize(WIDTH, HEIGHT), 8, 1);
IplImage *frameImage = NULL;
IplImage *notImage = NULL;
while(1){
cvWaitKey(1);
cvSplit(frameImage, a, b, c, NULL);
//detect objec from a,b,c.....output is "detecImg"
cvSetImageROI( detectImg, Roi); //Roi is changing depends on detection result
notImage=cvCreateImage( cvSize(Roi.width, Roi.height), 8, 1 );
cvNot(notImage, notImage);
copyNotImg= cvCloneImage(notImage);
... continues ...
}
任何见解都将不胜感激。
【问题讨论】:
标签: c++ opencv memory-leaks copy