Example #1
0
 def get_old_to_new_pose_mat(self, old_pose, new_pose):
     old_T_inv = self.pose_2d_to_mat_np(old_pose, inv=True)
     new_T = self.pose_2d_to_mat_np(new_pose, inv=False)
     mat = np.dot(new_T, old_T_inv)
     #mat = new_T
     mat_t = np_to_tensor(mat)
     return mat_t
Example #2
0
 def get_old_to_new_pose_mat(self, old_pose, new_pose):
     old_T_inv = self.pose_2d_to_mat_np(old_pose,
                                        self.source_map_size_px,
                                        inv=True)
     new_T = self.pose_2d_to_mat_np(new_pose,
                                    self.dest_map_size_px,
                                    inv=False)
     mat = np.dot(new_T, old_T_inv)
     #mat = new_T
     mat_t = np_to_tensor(mat, cuda=False)
     return mat_t
Example #3
0
 def get_old_to_new_pose_matrices(self, old_pose, new_pose):
     old_T_inv = self.poses_2d_to_mat_np(old_pose,
                                         self.source_map_size_px,
                                         inv=True)
     new_T = self.poses_2d_to_mat_np(new_pose,
                                     self.dest_map_size_px,
                                     inv=False)
     mat = np.matmul(new_T, old_T_inv)
     #mat = new_T
     mat_t = np_to_tensor(mat, insert_batch_dim=False, cuda=False)
     return mat_t
Example #4
0
    def get_pytorch_to_img_mat(self, img_size, inv=False):
        """
        Returns an affine transformation matrix that takes an image in coordinate range [-1,1] and turns it
        into an image of coordinate range [W,H]
        :param img_size: (W,H)
        :return:
        """
        # First move the image so that the origin is in the top-left corner
        # (in pytorch, the origin is in the center of the image)
        """
        t1 = np.asarray([
            [1.0, 0, 1.0],
            [0, 1.0, 1.0],
            [0, 0, 1.0]
        ])

        # Then scale the image up to the required size
        scale_w = img_size[0] / 2
        scale_h = img_size[1] / 2
        t2 = np.asarray([
            [scale_h, 0, 0],
            [0, scale_w, 0],
            [0, 0, 1]
        ])
        """

        # First scale the image to pixel coordinates
        scale_w = img_size[0] / 2
        scale_h = img_size[1] / 2

        t1 = np.asarray([[scale_h, 0, 0], [0, scale_w, 0], [0, 0, 1]])

        # Then move it such that the corner is at the origin
        t2 = np.asarray([[1.0, 0, scale_h], [0, 1.0, scale_w], [0, 0, 1.0]])

        T = np.dot(t2, t1)

        if inv:
            T = np.linalg.inv(T)

        T_t = np_to_tensor(T, cuda=False)

        return T_t