この方程式を実装して、ユーザーが選択した3つのポイントから円の中心を決定しようとしています: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で使用される座標系が画像の左上に原点を持っているという事実と関係があるのでしょうか(画像内の点はまだ正であるため、少なくとも垂直方向に「後方」にカウントしていると言えます。 )。
それともその推測は間違っていますか?