【发布时间】:2016-07-22 16:02:04
【问题描述】:
我有一个使用 OpenCV 的网络摄像头供稿,我正在尝试实时拟合椭圆。
我目前使用的代码有效,但很多时候它无法将椭圆拟合到图像中。我还可以追求哪些其他椭圆拟合图像的方法?
当前代码:
def find_ellipses(img): #img is grayscale image of what I want to fit
ret,thresh = cv2.threshold(img,127,255,0)
_,contours,hierarchy = cv2.findContours(thresh, 1, 2)
if len(contours) != 0:
for cont in contours:
if len(cont) < 5:
break
elps = cv2.fitEllipse(cont)
return elps #only returns one ellipse for now
return None
elps 的格式为 (x_centre,y_centre),(minor_axis,major_axis),angle
这是我想要成功拟合椭圆的示例。当我不想要这张图片时,我当前的代码失败了。
【问题讨论】: