Simplify triangulation API with config struct
This commit is contained in:
+37
-36
@@ -39,8 +39,15 @@ def load_case(camera_path: str, pose_path: str):
|
||||
pose_data = json.load(file)
|
||||
|
||||
poses_2d, person_counts = rpt.pack_poses_2d(pose_data["2D"], joint_count=len(JOINT_NAMES))
|
||||
cameras = rpt.convert_cameras(camera_data["cameras"])
|
||||
return poses_2d, person_counts, cameras
|
||||
return poses_2d, person_counts, camera_data["cameras"]
|
||||
|
||||
|
||||
def make_config(cameras, roomparams) -> rpt.TriangulationConfig:
|
||||
return rpt.make_triangulation_config(
|
||||
cameras,
|
||||
np.asarray(roomparams, dtype=np.float32),
|
||||
JOINT_NAMES,
|
||||
)
|
||||
|
||||
|
||||
def test_camera_structure_repr():
|
||||
@@ -69,14 +76,8 @@ def test_camera_structure_repr():
|
||||
)
|
||||
def test_triangulate_samples(camera_path: str, pose_path: str, roomparams):
|
||||
poses_2d, person_counts, cameras = load_case(camera_path, pose_path)
|
||||
poses_3d = rpt.triangulate_poses(
|
||||
poses_2d,
|
||||
person_counts,
|
||||
cameras,
|
||||
np.asarray(roomparams, dtype=np.float32),
|
||||
JOINT_NAMES,
|
||||
min_match_score=0.95,
|
||||
)
|
||||
config = make_config(cameras, roomparams)
|
||||
poses_3d = rpt.triangulate_poses(poses_2d, person_counts, config)
|
||||
|
||||
assert isinstance(poses_3d, np.ndarray)
|
||||
assert poses_3d.dtype == np.float32
|
||||
@@ -88,14 +89,10 @@ def test_triangulate_samples(camera_path: str, pose_path: str, roomparams):
|
||||
|
||||
def test_triangulate_repeatability():
|
||||
poses_2d, person_counts, cameras = load_case("data/p1/sample.json", "tests/poses_p1.json")
|
||||
roomparams = np.asarray([[5.6, 6.4, 2.4], [0.0, -0.5, 1.2]], dtype=np.float32)
|
||||
config = make_config(cameras, [[5.6, 6.4, 2.4], [0.0, -0.5, 1.2]])
|
||||
|
||||
first = rpt.triangulate_poses(
|
||||
poses_2d, person_counts, cameras, roomparams, JOINT_NAMES, min_match_score=0.95
|
||||
)
|
||||
second = rpt.triangulate_poses(
|
||||
poses_2d, person_counts, cameras, roomparams, JOINT_NAMES, min_match_score=0.95
|
||||
)
|
||||
first = rpt.triangulate_poses(poses_2d, person_counts, config)
|
||||
second = rpt.triangulate_poses(poses_2d, person_counts, config)
|
||||
|
||||
np.testing.assert_allclose(first, second, rtol=1e-5, atol=1e-5)
|
||||
|
||||
@@ -119,28 +116,21 @@ def test_build_pair_candidates_exposes_cartesian_view_pairs():
|
||||
|
||||
def test_triangulate_accepts_empty_previous_poses():
|
||||
poses_2d, person_counts, cameras = load_case("data/p1/sample.json", "tests/poses_p1.json")
|
||||
roomparams = np.asarray([[5.6, 6.4, 2.4], [0.0, -0.5, 1.2]], dtype=np.float32)
|
||||
config = make_config(cameras, [[5.6, 6.4, 2.4], [0.0, -0.5, 1.2]])
|
||||
empty_previous = np.zeros((0, len(JOINT_NAMES), 4), dtype=np.float32)
|
||||
|
||||
baseline = rpt.triangulate_poses(poses_2d, person_counts, cameras, roomparams, JOINT_NAMES)
|
||||
with_previous = rpt.triangulate_poses(
|
||||
poses_2d,
|
||||
person_counts,
|
||||
cameras,
|
||||
roomparams,
|
||||
JOINT_NAMES,
|
||||
empty_previous,
|
||||
)
|
||||
baseline = rpt.triangulate_poses(poses_2d, person_counts, config)
|
||||
with_previous = rpt.triangulate_poses(poses_2d, person_counts, config, empty_previous)
|
||||
|
||||
np.testing.assert_allclose(with_previous, baseline, rtol=1e-5, atol=1e-5)
|
||||
|
||||
|
||||
def test_triangulate_debug_matches_final_output():
|
||||
poses_2d, person_counts, cameras = load_case("data/h1/sample.json", "tests/poses_h1.json")
|
||||
roomparams = np.asarray([[4.8, 6.0, 2.0], [0.0, 0.0, 1.0]], dtype=np.float32)
|
||||
config = make_config(cameras, [[4.8, 6.0, 2.0], [0.0, 0.0, 1.0]])
|
||||
|
||||
final_poses = rpt.triangulate_poses(poses_2d, person_counts, cameras, roomparams, JOINT_NAMES)
|
||||
trace = rpt.triangulate_debug(poses_2d, person_counts, cameras, roomparams, JOINT_NAMES)
|
||||
final_poses = rpt.triangulate_poses(poses_2d, person_counts, config)
|
||||
trace = rpt.triangulate_debug(poses_2d, person_counts, config)
|
||||
|
||||
np.testing.assert_allclose(trace.final_poses, final_poses, rtol=1e-5, atol=1e-5)
|
||||
assert len(trace.pairs) >= len(trace.core_proposals)
|
||||
@@ -152,14 +142,13 @@ def test_triangulate_debug_matches_final_output():
|
||||
|
||||
def test_filter_pairs_with_previous_poses_returns_debug_matches():
|
||||
poses_2d, person_counts, cameras = load_case("data/p1/sample.json", "tests/poses_p1.json")
|
||||
roomparams = np.asarray([[5.6, 6.4, 2.4], [0.0, -0.5, 1.2]], dtype=np.float32)
|
||||
previous_poses = rpt.triangulate_poses(poses_2d, person_counts, cameras, roomparams, JOINT_NAMES)
|
||||
config = make_config(cameras, [[5.6, 6.4, 2.4], [0.0, -0.5, 1.2]])
|
||||
previous_poses = rpt.triangulate_poses(poses_2d, person_counts, config)
|
||||
|
||||
debug = rpt.filter_pairs_with_previous_poses(
|
||||
poses_2d,
|
||||
person_counts,
|
||||
cameras,
|
||||
JOINT_NAMES,
|
||||
config,
|
||||
previous_poses,
|
||||
)
|
||||
|
||||
@@ -171,12 +160,12 @@ def test_filter_pairs_with_previous_poses_returns_debug_matches():
|
||||
|
||||
def test_triangulate_does_not_mutate_inputs():
|
||||
poses_2d, person_counts, cameras = load_case("data/h1/sample.json", "tests/poses_h1.json")
|
||||
roomparams = np.asarray([[4.8, 6.0, 2.0], [0.0, 0.0, 1.0]], dtype=np.float32)
|
||||
config = make_config(cameras, [[4.8, 6.0, 2.0], [0.0, 0.0, 1.0]])
|
||||
|
||||
poses_before = poses_2d.copy()
|
||||
counts_before = person_counts.copy()
|
||||
|
||||
rpt.triangulate_poses(poses_2d, person_counts, cameras, roomparams, JOINT_NAMES)
|
||||
rpt.triangulate_poses(poses_2d, person_counts, config)
|
||||
|
||||
np.testing.assert_array_equal(poses_2d, poses_before)
|
||||
np.testing.assert_array_equal(person_counts, counts_before)
|
||||
@@ -219,3 +208,15 @@ def test_pack_poses_2d_rejects_inconsistent_joint_count():
|
||||
def test_pack_poses_2d_rejects_invalid_last_dimension():
|
||||
with pytest.raises(ValueError, match="shape"):
|
||||
rpt.pack_poses_2d([np.zeros((1, 2, 2), dtype=np.float32)])
|
||||
|
||||
|
||||
def test_make_triangulation_config_builds_bound_struct():
|
||||
_, _, cameras = load_case("data/p1/sample.json", "tests/poses_p1.json")
|
||||
config = make_config(cameras, [[5.6, 6.4, 2.4], [0.0, -0.5, 1.2]])
|
||||
|
||||
assert isinstance(config, rpt.TriangulationConfig)
|
||||
assert len(config.cameras) > 0
|
||||
np.testing.assert_allclose(config.roomparams, [[5.6, 6.4, 2.4], [0.0, -0.5, 1.2]])
|
||||
assert config.joint_names == JOINT_NAMES
|
||||
assert config.options.min_match_score == pytest.approx(0.95)
|
||||
assert config.options.min_group_size == 1
|
||||
|
||||
Reference in New Issue
Block a user