コード例 #1
0
    def run(self, file_path, opensfm_config, self_compute=False, self_path=''):
        #data = dataset.DataSet(args.dataset)
        reconstructions = opensfm_interface.load_reconstruction(file_path)
        no_cameras = True
        no_points = False

        if reconstructions:
            self.save_ply(file_path, reconstructions[0], None, no_cameras,
                          no_points)

        if False and reconstructions:
            udata = opensfm_interface.UndistortedDataSet(
                file_path, opensfm_config, 'undistorted', self_compute,
                self_path)
            for id, shot in reconstructions[0].shots.items():
                rgb = udata.load_undistorted_image(id)
                for t in ('clean', 'raw'):
                    path_depth = udata._depthmap_file(id, t + '.npz')
                    if not os.path.exists(path_depth):
                        continue
                    depth = np.load(path_depth)['depth']
                    rgb = scale_down_image(rgb, depth.shape[1], depth.shape[0])
                    ply = depthmap_to_ply(shot, depth, rgb)
                    with io.open_wt(udata._depthmap_file(id,
                                                         t + '.ply')) as fout:
                        fout.write(ply)
コード例 #2
0
ファイル: export_ply.py プロジェクト: ragarciafran/OpenSfM
    def run(self, args):
        data = dataset.DataSet(args.dataset)
        reconstructions = data.load_reconstruction()
        no_cameras = args.no_cameras
        no_points = args.no_points
        _all = args.all
        path_all = args.dataset + "/reconstruction_files/"

        if reconstructions and not _all:
            data.save_ply(reconstructions[0], None, no_cameras, no_points)

        elif reconstructions and _all:
            if not os.path.isdir(path_all):
                os.mkdir(path_all)
            for r in range(len(reconstructions)):
                data.save_ply(
                    reconstructions[r],
                    "reconstruction_files/reconstruction_" + str(r) + ".ply",
                    no_cameras, no_points)

        if args.depthmaps and reconstructions:
            udata = dataset.UndistortedDataSet(data, 'undistorted')
            for id, shot in reconstructions[0].shots.items():
                rgb = udata.load_undistorted_image(id)
                for t in ('clean', 'raw'):
                    path_depth = udata._depthmap_file(id, t + '.npz')
                    if not os.path.exists(path_depth):
                        continue
                    depth = np.load(path_depth)['depth']
                    rgb = scale_down_image(rgb, depth.shape[1], depth.shape[0])
                    ply = depthmap_to_ply(shot, depth, rgb)
                    with io.open_wt(udata._depthmap_file(id,
                                                         t + '.ply')) as fout:
                        fout.write(ply)
コード例 #3
0
ファイル: export_ply.py プロジェクト: wulun0102/OpenSfM
def run_dataset(data, no_cameras, no_points, depthmaps):
    """ Export reconstruction to PLY format

    Args:
        no_cameras: do not save camera positions
        no_points: do not save points
        depthmaps: export per-image depthmaps as pointclouds

    """

    reconstructions = data.load_reconstruction()
    no_cameras = no_cameras
    no_points = no_points

    if reconstructions:
        data.save_ply(reconstructions[0], None, no_cameras, no_points)

    if depthmaps and reconstructions:
        udata = dataset.UndistortedDataSet(data, 'undistorted')
        for id, shot in reconstructions[0].shots.items():
            rgb = udata.load_undistorted_image(id)
            for t in ('clean', 'raw'):
                path_depth = udata._depthmap_file(id, t + '.npz')
                if not os.path.exists(path_depth):
                    continue
                depth = np.load(path_depth)['depth']
                rgb = scale_down_image(rgb, depth.shape[1], depth.shape[0])
                ply = depthmap_to_ply(shot, depth, rgb)
                with io.open_wt(udata._depthmap_file(id, t + '.ply')) as fout:
                    fout.write(ply)
コード例 #4
0
def test_depthmap_to_ply():
    height, width = 2, 3

    camera = pygeometry.Camera.create_perspective(0.8, 0.0, 0.0)
    camera.id = "cam1"
    camera.height = height
    camera.width = width
    r = types.Reconstruction()
    r.add_camera(camera)
    shot = r.create_shot("shot1", camera.id,
                         pygeometry.Pose([0.0, 0.0, 0.0], [0.0, 0.0, 0.0]))

    image = np.zeros((height, width, 3))
    depth = np.ones((height, width))

    ply = dense.depthmap_to_ply(shot, depth, image)
    assert len(ply.splitlines()) == 16
コード例 #5
0
def test_depthmap_to_ply():
    height, width = 2, 3

    camera = pygeometry.Camera.create_perspective(0.8, 0.0, 0.0)
    camera.id = 'cam1'
    camera.height = height
    camera.width = width

    shot = types.Shot()
    shot.id = 'shot1'
    shot.camera = camera
    shot.pose = types.Pose([0.0, 0.0, 0.0], [0.0, 0.0, 0.0])

    image = np.zeros((height, width, 3))
    depth = np.ones((height, width))

    ply = dense.depthmap_to_ply(shot, depth, image)
    assert len(ply.splitlines()) == 16
コード例 #6
0
ファイル: export_ply.py プロジェクト: mapillary/OpenSfM
    def run(self, args):
        data = dataset.DataSet(args.dataset)
        reconstructions = data.load_reconstruction()
        no_cameras = args.no_cameras
        no_points = args.no_points

        if reconstructions:
            data.save_ply(reconstructions[0], None, no_cameras, no_points)

        if args.depthmaps and reconstructions:
            for id, shot in reconstructions[0].shots.items():
                rgb = data.load_undistorted_image(id)
                for t in ('clean', 'raw'):
                    path_depth = data._depthmap_file(id, t + '.npz')
                    if not os.path.exists(path_depth):
                        continue
                    depth = np.load(path_depth)['depth']
                    rgb = scale_down_image(rgb, depth.shape[1], depth.shape[0])
                    ply = depthmap_to_ply(shot, depth, rgb)
                    with io.open_wt(data._depthmap_file(id, t + '.ply')) as fout:
                        fout.write(ply)
コード例 #7
0
ファイル: test_dense.py プロジェクト: arjunkurup/scanner-3d
def test_depthmap_to_ply():
    height, width = 2, 3

    camera = types.PerspectiveCamera()
    camera.id = 'cam1'
    camera.focal = 0.8
    camera.k1 = 0.0
    camera.k2 = 0.0
    camera.height = height
    camera.width = width

    shot = types.Shot()
    shot.id = 'shot1'
    shot.camera = camera
    shot.pose = types.Pose([0.0, 0.0, 0.0], [0.0, 0.0, 0.0])

    image = np.zeros((height, width, 3))
    depth = np.ones((height, width))

    ply = dense.depthmap_to_ply(shot, depth, image)
    assert len(ply.splitlines()) == 16
コード例 #8
0
ファイル: test_dense.py プロジェクト: originlake/OpenSfM
def test_depthmap_to_ply() -> None:
    height, width = 2, 3

    camera = pygeometry.Camera.create_perspective(0.8, 0.0, 0.0)
    camera.id = "cam1"
    camera.height = height
    camera.width = width
    r = types.Reconstruction()
    r.add_camera(camera)
    shot = r.create_shot(
        # pyre-fixme[6]: For 1st param expected `ndarray` but got `List[float]`.
        # pyre-fixme[6]: For 2nd param expected `ndarray` but got `List[float]`.
        "shot1",
        camera.id,
        pygeometry.Pose([0.0, 0.0, 0.0], [0.0, 0.0, 0.0]))

    image = np.zeros((height, width, 3))
    depth = np.ones((height, width))

    ply = dense.depthmap_to_ply(shot, depth, image)
    assert len(ply.splitlines()) == 16
コード例 #9
0
ファイル: export_ply.py プロジェクト: HaifengDeng0709/OpenSfM
def run_dataset(data: DataSet, no_cameras, no_points, depthmaps,
                point_num_views):
    """Export reconstruction to PLY format

    Args:
        no_cameras: do not save camera positions
        no_points: do not save points
        depthmaps: export per-image depthmaps as pointclouds
        point_num_views: Export the number of views associated with each point

    """

    reconstructions = data.load_reconstruction()
    tracks_manager = data.load_tracks_manager()
    no_cameras = no_cameras
    no_points = no_points
    point_num_views = point_num_views

    if reconstructions:
        data.save_ply(reconstructions[0], tracks_manager, None, no_cameras,
                      no_points, point_num_views)

    if depthmaps:
        udata = dataset.UndistortedDataSet(data)
        urec = udata.load_undistorted_reconstruction()[0]
        for shot in urec.shots.values():
            rgb = udata.load_undistorted_image(shot.id)
            for t in ("clean", "raw"):
                path_depth = udata.depthmap_file(shot.id, t + ".npz")
                if not os.path.exists(path_depth):
                    continue
                depth = np.load(path_depth)["depth"]
                rgb = scale_down_image(rgb, depth.shape[1], depth.shape[0])
                ply = depthmap_to_ply(shot, depth, rgb)
                with io.open_wt(udata.depthmap_file(shot.id,
                                                    t + ".ply")) as fout:
                    fout.write(ply)