所以我知道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)
FindNonZero()
和{
问题在fitEllipse()
中,打印结果显示它已关闭
打印输出(椭圆)产量
((270.2370300292969, 174.11227416992188), (130.22764587402344, 216.85084533691406), 116.81776428222656)
根据文档(好的,OCV2.4的文档,但是我认为这个函数的行为在3.2中没有改变),第3和第4个数字是旋转矩形的宽度和长度。但在这里,它们比实际需要的要小。在
我使用的是python2.7和opencv3.2
fitEllipse
函数工作正常,但输入错误。在你应该输入椭圆的轮廓,而不是椭圆内的所有点。在
使用边缘检测算法,例如
cv2.Canny
可以很容易地得到轮廓相关问题 更多 >
编程相关推荐