小编Dre*_*eko的帖子

求重叠椭圆的直径和面积(OpenCV,Python)

这是我在 Stackoverflow 上的第一个问题。我有点激动,如果说错了请原谅。我们从颜料中随机绘制有重叠和没有重叠的混合椭圆。我正在分享我正在处理的图像和我的代码。我不是 opencv 模块的专业人士,我编写的代码是受来源启发的研究结果。

我的代码的目的是,

使用 cv2.fitEllipse 方法检测随机绘制的有或没有重叠椭圆。接下来,找到检测到的椭圆的长轴、短轴和面积。

我的代码的问题实际上是这样的,

在重叠椭圆中,在正常情况下拟合椭圆时,应该拟合2个椭圆,但大约拟合6-7个椭圆,我无法达到我想要计算的值。

我愿意接受您的帮助,提前谢谢您。

示例图片: 图像中有或没有重叠的椭圆

import cv2
import numpy as np
import random as rng
import math

img = cv2.imread('overlapping_ellipses.png', 1)
imge= cv2.cvtColor(img,cv2.COLOR_RGB2BGR)
gray = cv2.cvtColor(imge, cv2.COLOR_BGR2GRAY)
blur = cv2.blur(gray, (2,2), 3)
edged = cv2.Canny(blur, 50, 100)
kernel= np.ones((2,2))
edged1 = cv2.dilate(edged, kernel, iterations=2)
edged2 = cv2.erode(edged1, kernel, iterations=2)

def thresh_callback(val):
 threshold = val

 canny_output = cv2.Canny(edged2, threshold, threshold * 4)
 contours, _ = cv2.findContours(canny_output, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
 minRect = [None]*len(contours)
 minEllipse = …
Run Code Online (Sandbox Code Playgroud)

python opencv ellipse area

2
推荐指数
1
解决办法
986
查看次数

标签 统计

area ×1

ellipse ×1

opencv ×1

python ×1