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

Function epipolar_distance

core/loss.py:87–113  ·  view source on GitHub ↗

copy from kornia

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

Source from the content-addressed store, hash-verified

85 return (out + eps).sqrt()
86
87def epipolar_distance(pts1, pts2, Fm, squared=False, eps = 1e-8):
88 '''
89 copy from kornia
90 '''
91 if not isinstance(Fm, torch.Tensor):
92 raise TypeError("Fm type is not a torch.Tensor. Got {}".format(type(Fm)))
93
94 if (len(Fm.shape) != 3) or not Fm.shape[-2:] == (3, 3):
95 raise ValueError("Fm must be a (*, 3, 3) tensor. Got {}".format(Fm.shape))
96
97 if pts1.size(-1) == 2:
98 pts1 = kornia.geometry.convert_points_to_homogeneous(pts1)
99
100 if pts2.size(-1) == 2:
101 pts2 = kornia.geometry.convert_points_to_homogeneous(pts2)
102
103 F_t: torch.Tensor = Fm.permute(0, 2, 1).contiguous()
104 line1_in_2: torch.Tensor = pts1 @ F_t
105
106 numerator: torch.Tensor = (pts2 * line1_in_2).sum(2).pow(2)
107
108 denominator_inv: torch.Tensor = 1.0 / (line1_in_2[..., :2].norm(2, dim=2).pow(2) + eps)
109 out: torch.Tensor = numerator * denominator_inv
110
111 if squared:
112 return out
113 return (out + eps).sqrt()
114
115def compute_transformation_loss(args, data, flow_est, type='BB1'):
116 device = flow_est.device

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected