kornia.tracking#
- class kornia.tracking.HomographyTracker(initial_matcher=None, fast_matcher=None, ransac=None, minimum_inliers_num=30)[source]#
Perform local-feature-based tracking of the target planar object in the sequence of the frames.
- Parameters:
initial_matcher (
Optional[Module], optional) – image matching module, e.g.LocalFeatureMatcherorLoFTR. Default:GFTTAffNetHardNet.fast_matcher (
Optional[Module], optional) – fast image matching module, e.g.LocalFeatureMatcherorLoFTR. Default:DescriptorMatcher.ransac (
Optional[Module], optional) – homography estimation module. Default:RANSAC.minimum_inliers_num (
int, optional) – threshold for number inliers for matching to be successful. RANSAC needs 4 correspondences, so fewer than 4 matches always count as a failed match, whatever this value is. Default:30
- property device: device#
Return the device used by the current target image tensor.
- Returns:
The
torch.devicewhereself.targetis allocated.
- property dtype: dtype#
Return the data type used by the current target image tensor.
- Returns:
The
torch.dtypeofself.target.
- match_initial(x)[source]#
Estimate a homography from the initial target frame to frame
x.- Parameters:
x (
Tensor) – Current frame tensor to match against the stored target image.- Return type:
- Returns:
A tuple
(H, is_valid)whereHis the estimated homography matrix andis_validindicates whether enough inliers were found.
The method updates keypoint counters, inlier statistics, and stores the estimated homography as
previous_homographyon success.
- reset_tracking()[source]#
Reset temporal tracking state from previously processed frames.
- Return type:
- Returns:
None.
- set_target(target)[source]#
Register a new target image and refresh cached matcher features.
- Parameters:
target (
Tensor) – Reference target image tensor used for subsequent matching.- Return type:
- Returns:
None.
The target’s features are extracted once here and reused for every frame, for three kinds of matcher:
LoFTR: itsextract_features()output is passed asfeatures0, in place ofimage0.LocalFeatureMatcher: thelafs,responsesanddescriptorsof itsextract_features()are passed aslafs0,responses0anddescriptors0, next toimage0.Any other matcher whose
extract_featuresattribute is atorch.nn.Module: every entry of the dict it returns is passed with a0suffix (descasdesc0), next toimage0.
Other matchers get no cached representation and receive
image0andimage1only. A matcher replaced after this call, or atargetreassigned directly, gets the target’s features extracted again on its next use. Setting a target starts a new track: the previous homography maps the old target’s coordinates, so it is cleared. Atargetreassigned directly starts a new track too, on the nextforward()ortrack_next_frame().
- track_next_frame(x)[source]#
Track the target in frame
xusing the previous homography prior.- Parameters:
x (
Tensor) – Current frame tensor to align with the target image.- Return type:
- Returns:
A tuple
(H, is_valid)whereHis the updated homography andis_validindicates whether tracking remained reliable.
The frame is first prewarped by the inverse of the previous homography, then matched with
fast_matcherand verified using RANSAC.