コード例 #1
0
ファイル: test_bundle.py プロジェクト: ziweiWWANG/OpenSfM
def test_bundle_projection_fixed_internals(scene_synthetic):
    reference = scene_synthetic[0].get_reconstruction()
    camera_priors = {c.id: c for c in scene_synthetic[0].cameras}
    graph = tracking.as_graph(scene_synthetic[5])
    # Create the connnections in the reference
    for point_id in reference.points.keys():
        if point_id in graph:
            for shot_id, g_obs in graph[point_id].items():
                color = g_obs["feature_color"]
                pt = g_obs["feature"]
                obs = pysfm.Observation(
                    pt[0],
                    pt[1],
                    g_obs["feature_scale"],
                    g_obs["feature_id"],
                    color[0],
                    color[1],
                    color[2],
                )
                reference.map.add_observation(shot_id, point_id, obs)

    orig_camera = copy.deepcopy(reference.cameras["1"])

    custom_config = config.default_config()
    custom_config["bundle_use_gps"] = False
    custom_config["optimize_camera_parameters"] = False
    reconstruction.bundle(reference, camera_priors, [], custom_config)

    assert _projection_errors_std(reference.points) < 5e-3
    assert reference.cameras["1"].focal == orig_camera.focal
    assert reference.cameras["1"].k1 == orig_camera.k1
    assert reference.cameras["1"].k2 == orig_camera.k2
コード例 #2
0
 def load_config(self):
     config_file_path = self._config_file()
     if self.io_handler.isfile(config_file_path):
         with self.io_handler.open(config_file_path) as f:
             self.config = config.load_config_from_fileobject(f)
     else:
         self.config = config.default_config()
コード例 #3
0
ファイル: test_bundle.py プロジェクト: yummy123866/OpenSfM
def test_bundle_alignment_prior():
    """Test that cameras are aligned to have the Y axis pointing down."""
    camera = pygeometry.Camera.create_perspective(1.0, 0.0, 0.0)
    camera.id = 'camera1'

    shot = types.Shot()
    shot.id = '1'
    shot.camera = camera
    shot.pose = types.Pose(np.random.rand(3), np.random.rand(3))
    shot.metadata = types.ShotMetadata()
    shot.metadata.gps_position = [0, 0, 0]
    shot.metadata.gps_dop = 1

    r = types.Reconstruction()
    r.add_camera(camera)
    r.add_shot(shot)
    graph = nx.Graph()
    camera_priors = {camera.id: camera}
    gcp = []
    myconfig = config.default_config()

    reconstruction.bundle(graph, r, camera_priors, gcp, myconfig)

    assert np.allclose(shot.pose.translation, np.zeros(3))
    # up vector in camera coordinates is (0, -1, 0)
    assert np.allclose(shot.pose.transform([0, 0, 1]), [0, -1, 0])
コード例 #4
0
def test_absolute_pose_single_shot():
    """Single-camera resection on a toy reconstruction with
    1/1000 pixel noise and zero outliers."""
    parameters = config.default_config()
    synthetic_data, synthetic_tracks = synthetic_reconstruction()

    shot_id = 'shot1'
    camera_id = 'camera1'
    metadata = types.ShotMetadata()
    camera = synthetic_data.cameras[camera_id]

    graph_inliers = nx.Graph()
    shot_before = synthetic_data.shots[shot_id]
    status, report = reconstruction.resect(synthetic_tracks, graph_inliers,
                                           synthetic_data, shot_id, camera,
                                           metadata,
                                           parameters['resection_threshold'],
                                           parameters['resection_min_inliers'])
    shot_after = synthetic_data.shots[shot_id]

    assert status is True
    assert report['num_inliers'] == len(graph_inliers.edges())
    assert report['num_inliers'] is len(synthetic_data.points)
    np.testing.assert_almost_equal(shot_before.pose.rotation,
                                   shot_after.pose.rotation, 1)
    np.testing.assert_almost_equal(shot_before.pose.translation,
                                   shot_after.pose.translation, 1)
コード例 #5
0
ファイル: test_matching.py プロジェクト: AbegNext/OpenSfM-1
def test_match_using_words():
    configuration = config.default_config()
    nfeatures = 1000

    features, words = example_features(nfeatures, configuration)
    matches = pyfeatures.match_using_words(features[0], words[0],
                                           features[1], words[1][:, 0],
                                           configuration['lowes_ratio'],
                                           configuration['bow_num_checks'])
    assert len(matches) == nfeatures
    for i, j in matches:
        assert i == j
コード例 #6
0
ファイル: test_matching.py プロジェクト: AbegNext/OpenSfM-1
def test_robust_match():
    d = data_generation.CubeDataset(2, 100, 0.0, 0.3)
    p1 = np.array([v['feature'] for k, v in iteritems(d.tracks['shot0'])])
    p2 = np.array([v['feature'] for k, v in iteritems(d.tracks['shot1'])])
    camera1 = d.shots['shot0'].camera
    camera2 = d.shots['shot1'].camera
    num_points = len(p1)
    inlier_matches = np.array([(i, i) for i in range(num_points)])
    outlier_matches = np.random.randint(num_points, size=(num_points // 2, 2))
    matches = np.concatenate((inlier_matches, outlier_matches))
    rmatches = matching.robust_match(p1, p2, camera1, camera2, matches,
                                     config.default_config())
    assert num_points <= len(rmatches) <= len(matches)
コード例 #7
0
ファイル: test_bundle.py プロジェクト: zy20091082/OpenSfM
def test_bundle_projection_fixed_internals(scene_synthetic):
    reference = scene_synthetic[0].get_reconstruction()
    graph = scene_synthetic[5]
    adjusted = copy.deepcopy(reference)

    custom_config = config.default_config()
    custom_config['bundle_use_gps'] = False
    custom_config['optimize_camera_parameters'] = False
    reconstruction.bundle(graph, adjusted, {}, custom_config)

    assert _projection_errors_std(adjusted.points) < 5e-3
    assert reference.cameras['1'].focal == adjusted.cameras['1'].focal
    assert reference.cameras['1'].k1 == adjusted.cameras['1'].k1
    assert reference.cameras['1'].k2 == adjusted.cameras['1'].k2
コード例 #8
0
ファイル: odm_sfm.py プロジェクト: CosmosHua/GLD
def SfM_config(src, args):
    file = src + '/config.yaml'
    from opensfm.config import default_config
    if os.path.isfile(file):
        with open(file) as f:
            cfg = yaml.safe_load(f)
    else:
        cfg = default_config()  # cfg=dict

    if type(args) == str and os.path.isfile(args):
        with open(args) as f:
            args = yaml.safe_load(f)
    if type(args) == dict: cfg.update(args)
    if cfg['feature_type'] == 'ORB': cfg['matcher_type'] = 'BRUTEFORCE'
    feat_size(src, cfg)  # cfg['feature_process_size']
    with open(file, 'w') as f:  # update config.yaml
        f.write(yaml.dump(cfg, default_flow_style=False))
コード例 #9
0
def test_absolute_pose_generalized_shot():
    """Whole reconstruction resection (generalized pose) on a toy
    reconstruction with 0.01 meter point noise and zero outliers."""
    noise = 0.01
    parameters = config.default_config()
    scene, tracks = synthetic_reconstruction()
    cluster1, cluster2 = split_synthetic_reconstruction(
        scene, tracks, 3, noise)
    cluster2, translation, scale = move_and_scale_cluster(cluster2)

    status, T, inliers = reconstruction.\
        resect_reconstruction(cluster1, cluster2,
                              tracks, tracks,
                              2*noise,
                              parameters['resection_min_inliers'])

    assert status is True
    s, A, b = multiview.decompose_similarity_transform(T)
    np.testing.assert_almost_equal(scale, s, 2)
    np.testing.assert_almost_equal(np.eye(3), A, 2)
    np.testing.assert_almost_equal(translation, b, 2)
コード例 #10
0
def test_bundle_alignment_prior():
    """Test that cameras are aligned to have the Y axis pointing down."""
    camera = pygeometry.Camera.create_perspective(1.0, 0.0, 0.0)
    camera.id = "camera1"

    r = types.Reconstruction()
    r.add_camera(camera)
    shot = r.create_shot("1", camera.id,
                         pygeometry.Pose(np.random.rand(3), np.random.rand(3)))
    shot.metadata.gps_position.value = [0, 0, 0]
    shot.metadata.gps_accuracy.value = 1

    camera_priors = {camera.id: camera}
    gcp = []
    myconfig = config.default_config()

    reconstruction.bundle(r, camera_priors, gcp, myconfig)
    shot = r.shots[shot.id]
    assert np.allclose(shot.pose.translation, np.zeros(3))
    # up vector in camera coordinates is (0, -1, 0)
    assert np.allclose(shot.pose.transform([0, 0, 1]), [0, -1, 0])
コード例 #11
0
def test_bundle_void_gps_ignored() -> None:
    """Test that void gps values are ignored."""
    camera = pygeometry.Camera.create_perspective(1.0, 0.0, 0.0)
    camera.id = "camera1"

    r = types.Reconstruction()
    r.add_camera(camera)
    shot = r.create_shot("1", camera.id,
                         pygeometry.Pose(np.random.rand(3), np.random.rand(3)))

    camera_priors = {camera.id: camera}
    rig_priors = dict(r.rig_cameras.items())
    gcp = []
    myconfig = config.default_config()

    # Missing position
    shot.metadata.gps_position.value = np.zeros(3)
    shot.metadata.gps_accuracy.value = 1
    shot.metadata.gps_position.reset()
    shot.pose.set_origin(np.ones(3))
    reconstruction.bundle(r, camera_priors, rig_priors, gcp, myconfig)
    assert np.allclose(shot.pose.get_origin(), np.ones(3))

    # Missing accuracy
    shot.metadata.gps_position.value = np.zeros(3)
    shot.metadata.gps_accuracy.value = 1
    shot.metadata.gps_accuracy.reset()
    shot.pose.set_origin(np.ones(3))
    reconstruction.bundle(r, camera_priors, rig_priors, gcp, myconfig)
    assert np.allclose(shot.pose.get_origin(), np.ones(3))

    # Valid gps position and accuracy
    shot.metadata.gps_position.value = np.zeros(3)
    shot.metadata.gps_accuracy.value = 1
    shot.pose.set_origin(np.ones(3))
    reconstruction.bundle(r, camera_priors, rig_priors, gcp, myconfig)
    assert np.allclose(shot.pose.get_origin(), np.zeros(3))
コード例 #12
0
def test_absolute_pose_single_shot():
    """Single-camera resection on a toy reconstruction with
    1/1000 pixel noise and zero outliers."""
    parameters = config.default_config()
    synthetic_data, synthetic_tracks = synthetic_reconstruction()

    shot_id = 'shot1'
    camera_id = 'camera1'
    metadata = types.ShotMetadata()
    camera = synthetic_data.cameras[camera_id]

    shot_before = synthetic_data.shots[shot_id]
    status, report = reconstruction.resect(synthetic_tracks, synthetic_data,
                                           shot_id, camera, metadata,
                                           parameters['resection_threshold'],
                                           parameters['resection_min_inliers'])
    shot_after = synthetic_data.shots[shot_id]

    assert status is True
    assert report['num_inliers'] is len(synthetic_data.points)
    np.testing.assert_almost_equal(
        shot_before.pose.rotation, shot_after.pose.rotation, 1)
    np.testing.assert_almost_equal(
        shot_before.pose.translation, shot_after.pose.translation, 1)
コード例 #13
0
def test_bundle_alignment_prior() -> None:
    """Test that cameras are aligned to have the Y axis pointing down."""
    camera = pygeometry.Camera.create_perspective(1.0, 0.0, 0.0)
    camera.id = "camera1"

    r = types.Reconstruction()
    r.add_camera(camera)
    shot = r.create_shot("1", camera.id,
                         pygeometry.Pose(np.random.rand(3), np.random.rand(3)))
    # pyre-fixme[8]: Attribute has type `ndarray`; used as `List[int]`.
    shot.metadata.gps_position.value = [0, 0, 0]
    shot.metadata.gps_accuracy.value = 1

    camera_priors = {camera.id: camera}
    rig_priors = dict(r.rig_cameras.items())
    gcp = []
    myconfig = config.default_config()

    reconstruction.bundle(r, camera_priors, rig_priors, gcp, myconfig)
    shot = r.shots[shot.id]

    assert np.allclose(shot.pose.translation, np.zeros(3))
    # up vector in camera coordinates is (0, -1, 0)
    assert np.allclose(shot.pose.transform([0, 0, 1]), [0, -1, 0], atol=1e-7)
コード例 #14
0
def test_example_features():
    nfeatures = 1000

    features, words = example_features(nfeatures, config.default_config())
    assert len(features[0]) == nfeatures
    assert len(words[0]) == nfeatures