C++ opencv颜色检测内存泄漏
我试图创建一个程序,可以检测三种颜色的运动。 我只用一种颜色就做得很好 但是,当我再添加两个时,当我查看任务管理器时,程序会变得滞后,占用大量内存 调试之后,我发现了一段导致内存泄漏的代码C++ opencv颜色检测内存泄漏,c++,opencv,memory-leaks,C++,Opencv,Memory Leaks,我试图创建一个程序,可以检测三种颜色的运动。 我只用一种颜色就做得很好 但是,当我再添加两个时,当我查看任务管理器时,程序会变得滞后,占用大量内存 调试之后,我发现了一段导致内存泄漏的代码 void getMarkerPosition(IplImage* frame) { //create a blank image and assigned to 'imgTracking' which has the same size of original video imgTrackin
void getMarkerPosition(IplImage* frame)
{
//create a blank image and assigned to 'imgTracking' which has the same size of original video
imgTracking=cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U, 3);
cvZero(imgTracking); //covert the image, 'imgTracking' to black
IplImage* imgHSV2 = NULL;
imgHSV2 = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);
cvCvtColor(frame, imgHSV2, CV_BGR2HSV); //Change the color format from BGR to HSV
IplImage* imgThresh2 = NULL;
imgThresh2 = GetMarker2(imgHSV2);
trackMarker(imgThresh2, &startLineX, &startLineY);
imgThresh2 = GetMarker(imgHSV2);
trackMarker(imgThresh2, &endLineX, &endLineY);
startSection1=startLineX;
endSection1=startSection1+73;
startSection2=endSection1+6;
endSection2=startSection2+73;
startSection3=endSection2+6;
endSection3=startSection3+73;
startSection4=endSection3+6;
endSection4=startSection4+73;
startSection5=endSection4+6;
endSection5=startSection5+73;
startSection6=endSection5+6;
endSection6=startSection6+73;
startSection7=endSection6+6;
endSection7=startSection7+73;
cvLine(imgTracking,cv::Point(startLineX,startLineY-40) , cv::Point(endLineX,endLineY-40),cv::Scalar(0,200,0),2,8);
cvLine(imgTracking,cv::Point(startSection1,startLineY+20) , cv::Point(endSection1,endLineY+20),cv::Scalar(200,0,0),2,8);
cvLine(imgTracking,cv::Point(startSection2,startLineY+20) , cv::Point(endSection2,endLineY+20),cv::Scalar(200,0,0),2,8);
cvLine(imgTracking,cv::Point(startSection3,startLineY+20) , cv::Point(endSection3,endLineY+20),cv::Scalar(200,0,0),2,8);
cvLine(imgTracking,cv::Point(startSection4,startLineY+20) , cv::Point(endSection4,endLineY+20),cv::Scalar(200,0,0),2,8);
cvLine(imgTracking,cv::Point(startSection5,startLineY+20) , cv::Point(endSection5,endLineY+20),cv::Scalar(200,0,0),2,8);
cvLine(imgTracking,cv::Point(startSection6,startLineY+20) , cv::Point(endSection6,endLineY+20),cv::Scalar(200,0,0),2,8);
cvLine(imgTracking,cv::Point(startSection7,startLineY+20) , cv::Point(endSection7,endLineY+20),cv::Scalar(200,0,0),2,8);
// Add the tracking image and the frame
cvAdd(frame, imgTracking, frame);
}*/
但我的问题是,我不知道是哪个导致了内存泄漏。请帮我找到它在哪里
谢谢你的关注。我等待您的任何回复。如果您使用的是不推荐使用的c-api,您必须为我拥有的每个CVCreateImages调用cvReleaseImage,我将在我的main方法中释放该映像。我应该释放此功能中的图像吗?是!停止使用全局变量!有很好的理由,为什么他们切换到C++/CV::Mat和Suk.Err,你知道我能参考的任何表格吗?我不知道OpenCV C函数的OpenCV C++等价物