简体   繁体   English

轮廓的x,y轴长度的计算

[英]Calculation of contour's x,y-axis length

Good day everybody. 大家好

I am still working with the same old program and so far I managed to find the area and the coordinate of the biggest contour based on calculation of the contour's moments. 我仍在使用相同的旧程序 ,到目前为止,我已经根据轮廓力矩的计算找到了最大轮廓的面积和坐标。

double m_00 = cvGetSpatialMoment( &moments, 0, 0 ); //The area
double m_10 = cvGetSpatialMoment( &moments, 1, 0 );
double m_01 = cvGetSpatialMoment( &moments, 0, 1 );
float gravityX = (m_10 / m_00);     //center of x-axis              
float gravityY = (m_01 / m_00);     //center of y-axis

...and what I get is this: ...而我得到的是:

屏幕截图

...which is working nicely. ...效果很好。 But now I want to get the length of x-axis and y-axis of the contour/object, which is something like this: 但是现在我想获取轮廓/对象的x轴和y轴的长度,如下所示:

我需要的

The question is is there any function that can calculate the x-axis and y-axis length of the contour? 问题是, 是否有任何函数可以计算轮廓的x轴和y轴长度? If so, can anyone kindly give me some clue how to do it? 如果是这样,任何人都可以给我一些提示如何做吗?

Thanks in advance. 提前致谢。 Cheers. 干杯。

P/S: The program I linked above is the old one so it has some error in it. P / S:我上面链接的程序是旧程序 ,因此其中有些错误。

After I spend almost a day went around googling for the answer, I finally found an alternative way to get the width and the height of the object, which is by using cvBoundingRect function. 在花了将近一天的时间来搜寻答案之后,我终于找到了另一种获取对象宽度和高度的方法,即使用cvBoundingRect函数。 Basically it will make an upright bounding rectangle around the contour, so I just need to retrieve the width and the height of the box to get what I want. 基本上,它将在轮廓周围形成一个直立的边界矩形,因此我只需要获取框的宽度和高度即可得到所需的内容。

The code: 编码:

    Rect rect= cvBoundingRect(contour,0);
    double pt1, pt2;
    pt1 =rect.width;      //width
    pt2 =rect.height;     //heigth

BTW thanks for all your help. 顺便说一句谢谢您的所有帮助。 Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM