如何找到使用 cv.fitEllipse(contour) 获得的椭圆的面积? [英] How to find the area of an ellipse obtained using cv.fitEllipse(contour)?

查看:94
本文介绍了如何找到使用 cv.fitEllipse(contour) 获得的椭圆的面积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ellipse = cv2.fitEllipse(cnt) 得到一个椭圆.

I'm obtaining the an ellipse by using ellipse = cv2.fitEllipse(cnt).

它返回一个包含 3 个元素的元组,但我无法找到其中任何一个描述的内容.我想找到获得的椭圆的面积.我该怎么做.

It returns a tuple of 3 elements, but I'm unable to find what any of that depicts. I want to find the area of the ellipse obtained. How do I do it.

谢谢!

推荐答案

fitEllipse 返回三个元素的元组(如您所说),它们定义了椭圆的边界框.我将使用以下行来引用这些元素:

fitEllipse returns a tuple of three elements (as you say), which define the bounding box of the ellipse. I'll use the following line to reference those elements:

(x, y), (MA, ma), angle = cv2.fitEllipse(cnt)

这里唯一相关的信息是(MA, ma),它按顺序包含长轴和短轴的长度.椭圆的面积只是 pi 乘以长轴和短轴的乘积.(因此位置和旋转是不相关的.)所以你可以使用

The only relevant information here is (MA, ma), which contains the lengths of the major axis and minor axis, in that order. The area of an ellipse is simply pi times the product of the major axis and the minor axis. (Therefore the location and rotation are irrelevant.) So you would calculate the area of this ellipse using

A = PI * MA * ma

这篇关于如何找到使用 cv.fitEllipse(contour) 获得的椭圆的面积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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