在opencv序列中需要帮助!

时间:2011-07-06 07:14:31

标签: c opencv

我正在使用opencv序列来存储cvhoughline2产生的点数 我创建了序列并对其进行了一些操作,但是当我运行程序时,它会在行cvseqremove(seq,index)中断,并给出异常:

  
    内存位置的

异常

  

当我将光标放在cvseqremove(seq,index)的seq上时,它会写信给我:h_prev=0*000000000000000

我写了那段代码,我会感激任何帮助

void APPROXIMATE_LINES(IplImage* image,unsigned int xsize,unsigned int ysize,double width)
{
    unsigned int i;
    IplImage* color_dst = cvCreateImage(cvGetSize(image), 8,3);
    IplImage* dst = cvCreateImage(cvGetSize(image), 8,1);
    CvMemStorage* storage = cvCreateMemStorage(0);
    CvSeq* Filtered_Lines=0;
    boolean isbreak;
    double distance=4.0;
    CvPoint Mid_Point;
    CvPoint First_Mid_Point;
    CvSeq* lines = cvCreateSeq(CV_SEQ_ELTYPE_POINT,sizeof(CvSeq),sizeof(CvPoint),storage);
    cvCanny(image,dst,180,250,3);
    cvCvtColor(dst,color_dst,CV_GRAY2BGR);

    lines = cvHoughLines2(dst, storage, CV_HOUGH_PROBABILISTIC, 4, CV_PI/165, 95, 93, 75);
    while (lines->total>1)
    {
        CvPoint* First_Line = (CvPoint*)cvGetSeqElem(lines,0);
        First_Mid_Point=mid(First_Line[0],First_Line[1]);
        isbreak=FALSE;

        for( i =1; i < lines->total; i++ )
        {
            CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
            Mid_Point=mid(line[0],line[1]);
            if(dist(First_Mid_Point.x,First_Mid_Point.y,Mid_Point.x,Mid_Point.y)<distance)
            {
                cvSeqRemove(lines,i);
                isbreak=TRUE;
                break;
            }
        }       /*End_for*/

        if(!isbreak)
        {
            cvSeqPushFront(Filtered_Lines,First_Line); // <--- breaks here
            cvSeqRemove(lines,0);
        }
    } /*End_while*/


    for(i=0;i<Filterd_Lines;i++)
    {
        CvPoint* Filtered = (CvPoint*)cvGetSeqElem(Filterd_Lines,i);
        cvLine(color_dst, Filtered[0], Filtered[1], cvScalar(0,0,255,0),1,8,0);
    }

    cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    cvShowImage( "Example1",color_dst);
    cvWaitKey(0);
    cvReleaseImage( &color_dst);
    cvDestroyWindow( "Example1" );
}

1 个答案:

答案 0 :(得分:1)

功能签名是:

void cvSeqRemove(CvSeq* seq, int index)

但是你正在做的代码的一部分:

cvSeqRemove(lines,&i);

这意味着您传递变量i的内存地址而不是它的值,这不是您想要做的。

可能还有其他错误。