我正在尝试实现这个方程来确定三个用户选择的点的圆心:http ://en.wikipedia.org/wiki/Circumscribed_circle#Cartesian_coordinates
首先,通过这个 OpenCV 鼠标回调函数获取点并组装成一个列表:
def setupPoints(event, x, y, flags, points):
#Populates a provided list 'points' with
#three coordinates representing the edge of
#a circle
if points[0] == 0:
points[0] = (x,y)
elif points[1] == 0:
points[1] = (x,y)
else:
points[2] = (x,y)
然后我将点列表传递给这个函数,它完成了工作:
def findCircle(p):
#Returns the circle centre
#from three provided points provided as tuples
#in a list
#See http://en.wikipedia.org/wiki/Circumscribed_circle#Cartesian_coordinates
ax = float(p[0][0])
ay = float(p[0][1])
bx = float(p[1][0])
by = float(p[1][1])
cx = float(p[2][0])
cy = float(p[2][1])
d = 2*(ax*(by-cy)+bx*(cy-ay)+cx*(ay-by))
centrex = ((pow(ax,2)+pow(ay,2))*(by-cy)+(pow(bx,2)+pow(by,2))*(cy-ay)+(pow(cx,2)+pow(cy,2))*(ay-by))/d
centrey = ((pow(ax,2)+pow(ay,2))*(cx-bx)+(pow(bx,2)+pow(by,2))*(ax-cx)+(pow(cx,2)+pow(cy,2))*(bx-ax))/d
return (int(round(centrex)), int(round(centrey)), int(round(d)))
但是,它不起作用。返回的数字并没有大量关闭,但它们肯定是不正确的。这可能与 OpenCV 使用的坐标系的原点位于图像的左上角有关吗(图像内的点仍然是正数,因此可以说是“向后”计数,至少垂直)。
还是这个猜测错了?