def TPSMatch(self): mx1 = [] my1 = [] mx2 = [] my2 = [] for i in range(len(self.vMatchX)): mx1.append(self.X1[self.vMatchX[i]]) my1.append(self.Y1[self.vMatchX[i]]) mx2.append(self.X2[self.vMatchY[i]]) my2.append(self.Y2[self.vMatchY[i]]) tp = TPS() tp.drawimg = 0 self.vTPS = tp.GetTransform(mx1, my1, mx2, my2) if self.bDraw: self.DrawImg(mx1, my1, mx2, my2) return self.vTPS
def Chamfer(self): if (len(self.vMatchX) < 10): return [100000, 100000, 100000, 100000] PX1 = [] PY1 = [] PX2 = [] PY2 = [] for i in self.vMatchX: t = i % len(self.X1) PX1.append(self.X1[t]) PY1.append(self.Y1[t]) for i in self.vMatchY: PX2.append(self.X2[i]) PY2.append(self.Y2[i]) #print len(self.X1), len(self.X2) tp = TPS() tp.drawimg = self.bDraw bendingcost = tp.GetTransform(PX1, PY1, PX2, PY2) #DrawMatch(PX1, PY1, PX2, PY2) #print Afft chamfer = 0 resultx = [] resulty = [] for i in range(len(self.X1)): ts = tp.Transform(self.X1[i], self.Y1[i]) resultx.append(ts[0]) resulty.append(ts[1]) mindist = 1e10 for j in range(len(self.X2)): dist = math.sqrt((ts[0] - self.X2[j]) * (ts[0] - self.X2[j]) + (ts[1] - self.Y2[j]) * (ts[1] - self.Y2[j])) if (dist < mindist): mindist = dist chamfer += mindist #DrawMatch(self.X2, self.Y2, resultx, resulty) if (self.DrawImg): DrawIndexMatch(self.X1, self.Y1, self.X2, self.Y2, self.vMatchX, self.vMatchY) return bendingcost + [chamfer]