无法检测椭圆的明显尺寸

2024-09-29 23:30:53 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我知道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()和{}似乎工作正常。
问题在fitEllipse()中,打印结果显示它已关闭 打印输出(椭圆)产量

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

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

我使用的是python2.7和opencv3.2


Tags: the文档图像imageimportimgresthis

热门问题