def update_matricies(self):
# Build compatible arrays for cv2.getPerspectiveTransform
src = numpy.ones((4,2), dtype=numpy.float32)
dst = numpy.ones((4,2), dtype=numpy.float32)
src[:, :2] = self.align_handles[:4]
dst[:, :2] = corners
# And update the perspective transform
self.persp_matrix = cv2.getPerspectiveTransform(src, dst)
# Now, calculate the scale factor
da = self.dim_handles[1] - self.dim_handles[0]
db = self.dim_handles[3] - self.dim_handles[2]
ma = da.mag()
mb = db.mag()
sf = 100.0/max(ma, mb)
self.placeholder_dim_values[0] = sf * ma * MM
self.placeholder_dim_values[1] = sf * mb * MM
dims = self.__active_dims()
# Perspective transform handles - convert to
handles_pp = []
for handle in self.dim_handles:
p1 = self.persp_matrix.dot(handle.homol())
p1 /= p1[2]
handles_pp.append(p1[:2])
da = handles_pp[1] - handles_pp[0]
db = handles_pp[3] - handles_pp[2]
A = numpy.vstack([da**2, db**2])
B = numpy.array(dims) ** 2
res = numpy.abs(numpy.linalg.solve(A, B)) ** .5
self.scale_matrix = scale(res[0], res[1])
评论列表
文章目录