【问题标题】:How to find perimeter of multiple ellipses in an image? OpenCV,Python如何在图像中找到多个椭圆的周长? OpenCV,Python
【发布时间】:2021-02-16 12:46:56
【问题描述】:

我的图像有多个胎盘(白色和灰色的物体)。胎盘不是完整的椭圆。我已经在 OpenCV 中使用 fitEllipse 估计了完整的椭圆。但是,需要帮助找到估计椭圆的周长。

Image with multiple placentomes

Image with drawn ellipses in red on the placentomes

下面是我用来在胎盘上绘制椭圆的代码:-

img = cv2.imread('placentome.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
th, threshed = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY)
# Find countours of placentomes
cnts, hiers = cv2.findContours(threshed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2:]

# Draws ellipse onto objects using the contours found

for cnt in cnts:
  ellipse = cv2.fitEllipse(cnt)
  cv2.ellipse(img, ellipse, (0,0, 255), 1, cv2.LINE_AA)
   

【问题讨论】:

  • 欢迎来到 SO。请编辑您的帖子。并尝试更清楚地解释您的问题。您可以访问并查看how to ask a good question

标签: python opencv


【解决方案1】:

我假设您想计算图像中红色椭圆的周长。更多解释会很有用。

这个问题已经部分回答here。我将复制重要部分:
"函数fitEllipse返回一个包含椭圆所有参数的RotatedRect

一个椭圆由 5 个参数定义:

  • xc : 中心的 x 坐标
  • yc : 中心的y坐标
  • a : 长半轴
  • b : 次半轴
  • theta : 旋转角度

你可以像这样获取这些参数:

RotatedRect e = fitEllipse(points);

float xc    = e.center.x;
float yc    = e.center.y;
float a     = e.size.width  / 2;    // width >= height
float b     = e.size.height / 2;
float theta = e.angle;              // in degrees

获得椭圆的周长并不是一个简单的数学问题。可以用拉马努金方程推导出周长的近似解:

【讨论】:

    猜你喜欢
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    相关资源
    最近更新 更多