我使用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" );
}
函数签名为:
void cvSeqRemove(CvSeq* seq, int index)
但在你正在做的代码的一部分:
cvSeqRemove(lines,&i);
这意味着您传递的是变量i
的内存地址,而不是它的值,而这不是您想要做的
可能还有其他错误。