在opencv中查找轮廓的长度 [英] Finding length of contour in opencv

查看:539
本文介绍了在opencv中查找轮廓的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于在C中使用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\n",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.

编辑:draw_normal函数绘制传递给它的两个点之间的法线作为参数。

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

推荐答案


那么有没有办法找到轮廓的长度?

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

是的,您可以使用OpenCV标准函数找到轮廓的长度, cvarcLength()

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

在此处查看文档。

这篇关于在opencv中查找轮廓的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆