opencv颜色检测内存泄漏

时间:2014-01-16 18:05:56

标签: c++ opencv memory-leaks

我试图创建一个可以检测三种颜色运动的程序。 我用一种颜色做得很好

但是当我再添加两个时,程序变得迟钝并且当我查看任务管理器时会占用大量内存

调试后,我发现这段代码创建了内存泄漏代码

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);

} * /

但我的问题是,我不知道是哪个导致内存泄漏。请帮我找到它的位置。

让你注意。我等待你的任何回复。

0 个答案:

没有答案