1

OpenCV 方法 HoughLines2 是否存在从现在开始(版本 2.1.0.6)未修复的内存泄漏,或者我的这部分代码有问题?

CvMemStorage *storage = cvCreateMemStorage(0);
CvSeq *linesSeq = 0;
double smallL = 0.0, bigL=0.0, smallA = 0.0, bigA = 0.0;
linesSeq = cvHoughLines2(cannyImg, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180.0, 30, 50, 15);
for( int i = 0;i < linesSeq->total; i++ ){
    CvPoint* line = (CvPoint*)cvGetSeqElem(linesSeq,i);
    double sz = sqrt((line[0].x- line[1].x) *(line[0].x- line[1].x) + (line[0].y -line[1].y)*(line[0].y-line[1].y));
    if(sz < 70.0 ) smallL+=1.0;
    else bigL +=1.0;

    double deltaY = line[1].y - line[0].y;
    double deltaX = line[1].x - line[0].x;
    double angle;
    if ( abs(deltaX) > 1e-7){
        angle = atan2(deltaY, deltaX);

        if (angle < 0.1) smallA+=1.0;
        else bigA+=1.0;
    }else{

    }
 }

cvClearMemStorage(storage);
cvClearSeq(linesSeq);
cvReleaseImage(&cannyImg);

谢谢

4

1 回答 1

3

您正在使用cvClearMemStorage. 这不会释放内存,它只是重置一些指针。如果你想释放内存,你应该使用cvReleaseMemStorage(&storage)(顺便说一下,你不再需要cvClearSeq了,因为你会释放内存)。

于 2011-04-30T10:25:31.260 回答