MCPcopy Create free account
hub / github.com/drinkingcoder/NeuralMarker / symmetrical_epipolar_distance

Function symmetrical_epipolar_distance

core/loss.py:57–85  ·  view source on GitHub ↗

copy from kornia

(pts1, pts2, Fm, squared=False, eps = 1e-8)

Source from the content-addressed store, hash-verified

55 return dist.mean()
56
57def symmetrical_epipolar_distance(pts1, pts2, Fm, squared=False, eps = 1e-8):
58 '''
59 copy from kornia
60 '''
61 if not isinstance(Fm, torch.Tensor):
62 raise TypeError(f"Fm type is not a torch.Tensor. Got {type(Fm)}")
63
64 if (len(Fm.shape) != 3) or not Fm.shape[-2:] == (3, 3):
65 raise ValueError(f"Fm must be a (*, 3, 3) tensor. Got {Fm.shape}")
66
67 if pts1.size(-1) == 2:
68 pts1 = kornia.geometry.convert_points_to_homogeneous(pts1)
69
70 if pts2.size(-1) == 2:
71 pts2 = kornia.geometry.convert_points_to_homogeneous(pts2)
72
73 F_t: torch.Tensor = Fm.permute(0, 2, 1)
74 line1_in_2: torch.Tensor = pts1 @ F_t
75 line2_in_1: torch.Tensor = pts2 @ Fm
76
77 numerator: torch.Tensor = (pts2 * line1_in_2).sum(2).pow(2)
78 denominator_inv: torch.Tensor = 1.0 / (line1_in_2[..., :2].norm(2, dim=2).pow(2) + eps) + 1.0 / (
79 line2_in_1[..., :2].norm(2, dim=2).pow(2) + eps
80 )
81 out: torch.Tensor = numerator * denominator_inv
82
83 if squared:
84 return out
85 return (out + eps).sqrt()
86
87def epipolar_distance(pts1, pts2, Fm, squared=False, eps = 1e-8):
88 '''

Calls

no outgoing calls

Tested by

no test coverage detected