Finding contour length in opencv

This applies to the project, which concerns the detection of text in an image using OpenCV in C. The process is to detect colors inside and outside the corresponding contours, and the way to do this is to draw normals on the contours at an equal position distance and extract pixel colors at the corresponding positions of the end points normals.

I am trying to implement this using the following code, but it does not work. I mean, he draws normals, but not evenly and evenly.

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\n",x1,y1,x2,y2);
         draw_normals(x1,y1,x2,y2);
     }
}

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

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

+5
source share
1

?

, , OpenCV, cvarcLength().

+9

All Articles