gpt4 book ai didi

python - OpenCV的fitEllipse()无法检测到明显的椭圆的正确尺寸

转载 作者:行者123 更新时间:2023-12-02 17:42:02 26 4
gpt4 key购买 nike

所以我知道fitEllipse有一些不幸(请参阅this question for example),但是为什么在这里它无法完全找到明显的椭圆尺寸?
我想念什么吗?

import numpy as np
import cv2

img=cv2.imread(my_input_image,0)

#this will be the result image where I'll draw the found ellipse in red
img_res=cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)


nzs=cv2.findNonZero(img)

#calling fitEllipse on the non zeros
ellipse=cv2.fitEllipse(nzs)

#drawing the found ellipse
img_res=cv2.ellipse(img_res,ellipse,(0,0,255),thickness=3)

输入图像(8位二进制图像): enter image description here

输出图像(RBG):
enter image description here
FindNonZero()ellipse()似乎可以正常工作。
问题出在 fitEllipse()中,打印其结果表明它已关闭
打印输出(椭圆形)

((270.2370300292969, 174.11227416992188), (130.22764587402344, 216.85084533691406), 116.81776428222656)



根据文档(好的,OCV2.4文档,但我认为此功能的行为在3.2中没有更改),第3和第4个数字是旋转矩形的宽度和长度。但是在这里,它们比实际需要的要小。

我正在使用Python 2.7和OpenCV 3.2

最佳答案

fitEllipse函数可以正常运行,但是您输入了错误的信息。

您应该输入椭圆的轮廓,而不是椭圆内的所有点作为输入。

您可以使用边缘检测算法轻松获取轮廓,例如cv2.Canny

关于python - OpenCV的fitEllipse()无法检测到明显的椭圆的正确尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43324806/

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