Ejemplo n.º 1
0
    def fusion(self, depthmaps, Rs):
        """
        Fuse the rendered depth maps.

        :param depthmaps: depth maps
        :type depthmaps: numpy.ndarray
        :param Rs: rotation matrices corresponding to views
        :type Rs: [numpy.ndarray]
        :return: (T)SDF
        :rtype: numpy.ndarray
        """

        Ks = self.fusion_intrisics.reshape((1, 3, 3))
        Ks = np.repeat(Ks, len(depthmaps), axis=0).astype(np.float32)

        Ts = []
        for i in range(len(Rs)):
            Rs[i] = Rs[i]
            Ts.append(np.array([0, 0, 1]))

        Ts = np.array(Ts).astype(np.float32)
        Rs = np.array(Rs).astype(np.float32)

        depthmaps = np.array(depthmaps).astype(np.float32)
        views = libfusion.PyViews(depthmaps, Ks, Rs, Ts)

        # Note that this is an alias defined as libfusiongpu.tsdf_gpu or libfusioncpu.tsdf_cpu!
        return compute_tsdf(views, self.options.resolution,
                            self.options.resolution, self.options.resolution,
                            self.voxel_size, self.truncation, False)
Ejemplo n.º 2
0
    def fusion(self, depthmaps, Rs):
        """
        Fuse the rendered depth maps.

        :param depthmaps: depth maps
        :type depthmaps: numpy.ndarray
        :param Rs: rotation matrices corresponding to views
        :type Rs: [numpy.ndarray]
        :return: (T)SDF
        :rtype: numpy.ndarray
        """

        Ks = self.fusion_intrisics.reshape((1, 3, 3))
        Ks = np.repeat(Ks, len(depthmaps), axis=0).astype(np.float32)

        Ts = []
        for i in range(len(Rs)):
            Rs[i] = Rs[i]
            Ts.append(np.array([0, 0, 1]))

        data_dir = self.options.depth_dir.replace('depth', 'data')

        if not os.path.exists(data_dir):
            os.makedirs(data_dir)

        for i in range(len(Rs)):

            R = Rs[i]
            T = Ts[i]

            extrinsics = np.eye(4)
            extrinsics[:3, :3] = R
            extrinsics[:3, 3] = T
            np.savetxt(os.path.join(data_dir, '{}.extrinsics.txt'.format(i)),
                       extrinsics)

            intrinsics = self.fusion_intrisics
            np.savetxt(os.path.join(data_dir, '{}.intrinsics.txt'.format(i)),
                       intrinsics)

            depth = np.copy(depthmaps[i])
            depth *= 1000
            depth = depth.astype(np.uint16)
            cv2.imwrite(
                os.path.expanduser(
                    os.path.join(data_dir, '{}.depth.png'.format(i))), depth)

        Ts = np.array(Ts).astype(np.float32)
        Rs = np.array(Rs).astype(np.float32)

        depthmaps = np.array(depthmaps).astype(np.float32)
        views = libfusion.PyViews(depthmaps, Ks, Rs, Ts)

        # Note that this is an alias defined as libfusiongpu.tsdf_gpu or libfusioncpu.tsdf_cpu!
        return compute_tsdf(views, self.options.resolution,
                            self.options.resolution, self.options.resolution,
                            self.voxel_size, self.truncation, False)
def fusion(depthmaps, Rs):
    """
    Fuse the rendered depth maps.

    :param depthmaps: depth maps
    :type depthmaps: numpy.ndarray
    :param Rs: rotation matrices corresponding to views
    :type Rs: [numpy.ndarray]
    :return: (T)SDF
    :rtype: numpy.ndarray
    """

    Ks = np.array([[
        config['watertight_rendering']['focal_length_x'], 0,
        config['watertight_rendering']['principal_point_x']
    ],
                   [
                       0, config['watertight_rendering']['focal_length_y'],
                       config['watertight_rendering']['principal_point_y']
                   ], [0, 0, 1]])
    Ks = Ks.reshape((1, 3, 3))
    Ks = np.repeat(Ks, len(depthmaps), axis=0).astype(np.float32)

    Ts = []
    for i in range(len(Rs)):
        Rs[i] = Rs[i]
        Ts.append(np.array(config['watertight_rendering']['mesh_center']))

    Ts = np.array(Ts).astype(np.float32)
    Rs = np.array(Rs).astype(np.float32)

    depthmaps = np.array(depthmaps).astype(np.float32)
    views = libfusion.PyViews(depthmaps, Ks, Rs, Ts)

    # Note that this is an alias defined as libfusiongpu.tsdf_gpu or libfusioncpu.tsdf_cpu!
    return compute_tsdf(views, config['watertight_fusion']['resolution'],
                        config['watertight_fusion']['resolution'],
                        config['watertight_fusion']['resolution'],
                        config['watertight_fusion']['voxel_size'],
                        config['watertight_fusion']['truncation'], False)