gpt4 book ai didi

image-processing - opencv中求轮廓长度

转载 作者:太空宇宙 更新时间:2023-11-03 20:00:47 25 4
gpt4 key购买 nike

这是一个涉及使用 C 语言中的 OpenCV 检测图像中文本的项目。该过程是检测相应轮廓内部和外部的颜色,方法是在轮廓上以等间距绘制法线位置并提取法线端点对应位置的像素颜色。

我尝试使用以下代码来实现它,但它不起作用。我的意思是,它绘制的是法线,但不是等间距的。

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);
}
}

有没有办法找到轮廓的长度,以便我可以将其除以我想要绘制的法线数量。提前致谢。

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

最佳答案

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

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

Check Documentation here.

关于image-processing - opencv中求轮廓长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59247461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com