Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

image processing - Finding length of contour in opencv

This is regarding a project that concerns detection of text in an image using OpenCV in C. The process is to detect the colors inside and outside the corresponding contours and the way to do that is to draw normals on the contours in equal spaced positions and extract the pixel colors in the corresponding positions of the normals end-points.

I am trying to implement this using the following code but it's not working. I mean, its drawing the normals but not in and equi-spaced fashion.

for( ; contours!=0 ; contours = contours->h_next )
{
        CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );

        cvDrawContours( cc_color, contours, color, CV_RGB(0,0,0), -1, 1, 8, cvPoint(0,0) );
        ptr = contours;
        for( i=1; i<ptr->total; i++)
        {
         p1 = CV_GET_SEQ_ELEM( CvPoint, ptr, i );

         p2 = CV_GET_SEQ_ELEM( CvPoint, ptr, i+1 );

         x1 = p1->x;
         y1 = p1->y;

         x2 = p2->x;
         y2 = p2->y;
         printf("%d %d     %d %d
",x1,y1,x2,y2);
         draw_normals(x1,y1,x2,y2);
     }
}

So is there a way to find the length of a contour so that I can divide it by the number of normals I want to draw. Thanks in advance.

EDIT: The draw_normal function draws the normals between two points passed to it as parameters.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So is there a way to find the length of a contour?

Yes, you can find length of a contour using OpenCV standard function , cvarcLength().

Check Documentation here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...