Need help in opencv sequences !
I'm using opencv
sequences to store points resulted from cvhoughline2
.
cvseqremove(seq,index)
and gives me the exception:
exception at memory location
When I put the cursor on the seq in cvseqremove(seq,index)
, it writes to me: h_prev=0*000000000000000
.
I wrote that code, i'll appreciate any help
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)
{
cvSe开发者_Python百科qRemove(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" );
}
The function signature is:
void cvSeqRemove(CvSeq* seq, int index)
But on one part of the code you are doing:
cvSeqRemove(lines,&i);
Which means you are passing the memory address of the variable i
instead of it's value, and this is not what you want to do.
There might be other bugs.
精彩评论