Skip to content

Commit ba98adc

Browse files
committed
fix: keep vector_angle for single vector pairs.
1 parent b075045 commit ba98adc

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

opensfm/matching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def _compute_inliers_bearings(b1, b2, T, threshold=0.01):
122122
br2 = R.T.dot((p - t).T).T
123123
br2 /= np.linalg.norm(br2, axis=1)[:, np.newaxis]
124124

125-
ok1 = multiview.vector_angle(br1, b1) < threshold
126-
ok2 = multiview.vector_angle(br2, b2) < threshold
125+
ok1 = multiview.vector_angle_many(br1, b1) < threshold
126+
ok2 = multiview.vector_angle_many(br2, b2) < threshold
127127
return ok1 * ok2
128128

129129

opensfm/multiview.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,29 @@ def rq(A):
105105

106106

107107
def vector_angle(u, v):
108-
'''
108+
"""Angle between two vectors.
109+
110+
>>> u = [ 0.99500417, -0.33333333, -0.09983342]
111+
>>> v = [ 0.99500417, -0.33333333, -0.09983342]
112+
>>> vector_angle(u, v)
113+
0.0
114+
"""
115+
cos = np.dot(u, v) / math.sqrt(np.dot(u, u) * np.dot(v, v))
116+
if cos >= 1.0:
117+
return 0.0
118+
else:
119+
return math.acos(cos)
120+
121+
122+
def vector_angle_many(u, v):
123+
"""Angles between to lists of vectors.
124+
109125
>>> u = [[0.99500417, -0.33333333, -0.09983342], [0, -1, 0], [0, 1, 0]]
110126
>>> v = [[0.99500417, -0.33333333, -0.09983342], [0, +1, 0], [0, 0, 1]]
111-
>>> angles = vector_angle(u, v)
127+
>>> angles = vector_angle_many(u, v)
112128
>>> np.allclose(angles, [0., 3.1416, 1.5708])
113129
True
114-
'''
130+
"""
115131
ua = np.array(u, dtype=np.float64, copy=False).reshape(-1, 3)
116132
va = np.array(v, dtype=np.float64, copy=False).reshape(-1, 3)
117133
return tf.angle_between_vectors(ua, va, axis=1)

0 commit comments

Comments
 (0)