Merging two camera systems¶
When two camera systems (two rigs, or two recordings) see a common volume,
each produces its own trajectories in its own frame and the particles in the
overlap appear twice. flowtracks.merge provides the generic steps:
estimate_rigid_map()measures the rigid map between the two frames from particles both systems see in the same frame. For each candidate rotation the same-frame neighbour differences pile up at the true offset; the sharpest pile wins and the offset is refined on tight pairs. With no sharp pile it refuses (ValueError) rather than guess.apply_rigid()maps the second system’s positions (and, with zero offset, velocities and accelerations) into the first.overlap_counts()counts the same-frame shared points of every trajectory pair;best_partners()gives each trajectory its partner andduplicates()the second-system trajectories a keep-the-longer rule removes.
from flowtracks.merge import (apply_rigid, best_partners, duplicates,
estimate_rigid_map, overlap_counts)
rig = estimate_rigid_map(same_frame_point_pairs,
[("0", np.eye(3)), ("180", np.diag([-1, 1, -1]))])
pos_b_in_a = apply_rigid(pos_b, rig["matrix"], rig["offset"])
shared = overlap_counts(tracks_a, tracks_b, tol=20.0)
A complete use, with the facility’s own frame, walls and output layout, is
scripts/illmenau/merge_dual_rig.py in openptv2.
Merging trajectory datasets of two camera systems that see a common volume.
Two systems (two camera rigs, two recordings of one rig) each produce their own trajectories in their own coordinate frame. Where their volumes overlap the same particle appears twice. This module
1. measures the rigid map between the two frames from particles both systems
see in the same frame (estimate_rigid_map()): for each candidate
rotation, the same-frame neighbour differences pile up at the true offset;
the rotation whose pile is sharpest wins and the offset is refined on tight
pairs. No sharp pile means no common particles, and it refuses
(ValueError) rather than guess;
2. maps points of the second system into the first (apply_rigid());
3. finds the trajectory pairs that share same-frame points closer than a
tolerance (overlap_counts()), each trajectory’s best partner
(best_partners()) and the duplicates a keep-the-longer rule removes
(duplicates()).
Units are whatever the inputs use; tolerances are in the same unit.
- flowtracks.merge.estimate_rigid_map(pairs, rotations, search_radius=150.0, bin_size=6.0, tight=8.0, min_peak=50, min_ratio=100.0, refine=2, log=<built-in function print>)[source]¶
Rigid map from system B to system A:
p_A = R @ p_B - offset.Arguments
pairs: list of (points_A, points_B) arrays, (n, 3) and (m, 3), each pair taken in the same frame (use well-triangulated points only).rotations: list of (label, 3x3 matrix) candidates for R.search_radius: neighbours of a point of A within this distance of the rotated B points vote for the offset.bin_size: histogram bin of the votes; the offset is the densest bin.tight: pairs closer than this after the first estimate refine it.min_peak, min_ratio: the densest bin must hold at leastmin_peakvotes andmin_ratiotimes the mean, or the map is refused.refine: number of refinement passes (median of the tight pairs).log: callable for progress lines, or None.
Returns
dict with matrix (3x3), offset (3,), label of the chosen rotation, n_pairs (tight pairs of the last pass) and spread (median absolute deviation of their differences, per axis).
- flowtracks.merge.apply_rigid(points, matrix, offset=0.0)[source]¶
points @ matrix.T - offset: system-B points (or, with offset 0, velocities and accelerations) in system A’s frame.
- flowtracks.merge.overlap_counts(tracks_a, tracks_b, tol)[source]¶
Same-frame shared points of every trajectory pair of A and B.
Arguments
tracks_a, tracks_b: mappings id -> mapping with “time” (n,) and “pos” (n, 3), both in one frame of reference.tol: a point of A and the nearest point of B in the same frame closer than this count as shared.
Returns
{(id_a, id_b): number of shared points}