at master 8.6 kB view raw
1diff --git a/opensfm/exif.py b/opensfm/exif.py 2--- a/opensfm/exif.py 3+++ b/opensfm/exif.py 4@@ -509,7 +509,7 @@ class EXIF: 5 ) 6 ) 7 8- if np.all(ypr) is not None: 9+ if np.all(ypr != None): 10 ypr = np.radians(ypr) 11 12 # Convert YPR --> OPK 13diff --git a/opensfm/transformations.py b/opensfm/transformations.py 14--- a/opensfm/transformations.py 15+++ b/opensfm/transformations.py 16@@ -232,7 +232,7 @@ def translation_from_matrix(matrix: numpy.ndarray) -> numpy.ndarray: 17 True 18 19 """ 20- return numpy.array(matrix, copy=False)[:3, 3].copy() 21+ return numpy.asarray(matrix)[:3, 3].copy() 22 23 24 def reflection_matrix(point: numpy.ndarray, normal: numpy.ndarray) -> numpy.ndarray: 25@@ -275,7 +275,7 @@ def reflection_from_matrix( 26 True 27 28 """ 29- M = numpy.array(matrix, dtype=numpy.float64, copy=False) 30+ M = numpy.asarray(matrix, dtype=numpy.float64) 31 # normal: unit eigenvector corresponding to eigenvalue -1 32 w, V = numpy.linalg.eig(M[:3, :3]) 33 i = numpy.where(abs(numpy.real(w) + 1.0) < 1e-8)[0] 34@@ -339,7 +339,7 @@ def rotation_matrix( 35 M[:3, :3] = R 36 if point is not None: 37 # rotation not around origin 38- point = numpy.array(point[:3], dtype=numpy.float64, copy=False) 39+ point = numpy.asarray(point[:3], dtype=numpy.float64) 40 M[:3, 3] = point - numpy.dot(R, point) 41 return M 42 43@@ -359,7 +359,7 @@ def rotation_from_matrix( 44 True 45 46 """ 47- R = numpy.array(matrix, dtype=numpy.float64, copy=False) 48+ R = numpy.asarray(matrix, dtype=numpy.float64) 49 R33 = R[:3, :3] 50 # direction: unit eigenvector of R33 corresponding to eigenvalue of 1 51 w, W = numpy.linalg.eig(R33.T) 52@@ -444,7 +444,7 @@ def scale_from_matrix( 53 True 54 55 """ 56- M = numpy.array(matrix, dtype=numpy.float64, copy=False) 57+ M = numpy.asarray(matrix, dtype=numpy.float64) 58 M33 = M[:3, :3] 59 factor = numpy.trace(M33) - 2.0 60 try: 61@@ -505,11 +505,11 @@ def projection_matrix( 62 63 """ 64 M = numpy.identity(4) 65- point = numpy.array(point[:3], dtype=numpy.float64, copy=False) 66+ point = numpy.asarray(point[:3], dtype=numpy.float64) 67 normal = unit_vector(normal[:3]) 68 if perspective is not None: 69 # perspective projection 70- perspective = numpy.array(perspective[:3], dtype=numpy.float64, copy=False) 71+ perspective = numpy.asarray(perspective[:3], dtype=numpy.float64) 72 M[0, 0] = M[1, 1] = M[2, 2] = numpy.dot(perspective - point, normal) 73 M[:3, :3] -= numpy.outer(perspective, normal) 74 if pseudo: 75@@ -522,7 +522,7 @@ def projection_matrix( 76 M[3, 3] = numpy.dot(perspective, normal) 77 elif direction is not None: 78 # parallel projection 79- direction = numpy.array(direction[:3], dtype=numpy.float64, copy=False) 80+ direction = numpy.asarray(direction[:3], dtype=numpy.float64) 81 scale = numpy.dot(direction, normal) 82 M[:3, :3] -= numpy.outer(direction, normal) / scale 83 M[:3, 3] = direction * (numpy.dot(point, normal) / scale) 84@@ -569,7 +569,7 @@ def projection_from_matrix( 85 True 86 87 """ 88- M = numpy.array(matrix, dtype=numpy.float64, copy=False) 89+ M = numpy.asarray(matrix, dtype=numpy.float64) 90 M33 = M[:3, :3] 91 w, V = numpy.linalg.eig(M) 92 i = numpy.where(abs(numpy.real(w) - 1.0) < 1e-8)[0] 93@@ -726,7 +726,7 @@ def shear_from_matrix( 94 True 95 96 """ 97- M = numpy.array(matrix, dtype=numpy.float64, copy=False) 98+ M = numpy.asarray(matrix, dtype=numpy.float64) 99 M33 = M[:3, :3] 100 # normal: cross independent eigenvectors corresponding to the eigenvalue 1 101 w, V = numpy.linalg.eig(M33) 102@@ -790,7 +790,7 @@ def decompose_matrix( 103 True 104 105 """ 106- M = numpy.array(matrix, dtype=numpy.float64, copy=True).T 107+ M = numpy.asarray(matrix, dtype=numpy.float64, copy=True).T 108 if abs(M[3, 3]) < _EPS: 109 raise ValueError("M[3, 3] is zero") 110 M /= M[3, 3] 111@@ -982,8 +982,8 @@ def affine_matrix_from_points( 112 More examples in superimposition_matrix() 113 114 """ 115- v0 = numpy.array(v0, dtype=numpy.float64, copy=True) 116- v1 = numpy.array(v1, dtype=numpy.float64, copy=True) 117+ v0 = numpy.asarray(v0, dtype=numpy.float64, copy=True) 118+ v1 = numpy.asarray(v1, dtype=numpy.float64, copy=True) 119 120 ndims = v0.shape[0] 121 if ndims < 2 or v0.shape[1] < ndims or v0.shape != v1.shape: 122@@ -1099,8 +1099,8 @@ def superimposition_matrix( 123 True 124 125 """ 126- v0 = numpy.array(v0, dtype=numpy.float64, copy=False)[:3] 127- v1 = numpy.array(v1, dtype=numpy.float64, copy=False)[:3] 128+ v0 = numpy.asarray(v0, dtype=numpy.float64)[:3] 129+ v1 = numpy.asarray(v1, dtype=numpy.float64)[:3] 130 return affine_matrix_from_points(v0, v1, shear=False, scale=scale, usesvd=usesvd) 131 132 133@@ -1198,7 +1198,7 @@ def euler_from_matrix( 134 j = _NEXT_AXIS[i + parity] 135 k = _NEXT_AXIS[i - parity + 1] 136 137- M = numpy.array(matrix, dtype=numpy.float64, copy=False)[:3, :3] 138+ M = numpy.asarray(matrix, dtype=numpy.float64)[:3, :3] 139 if repetition: 140 sy = math.sqrt(M[i, j] * M[i, j] + M[i, k] * M[i, k]) 141 if sy > _EPS: 142@@ -1329,7 +1329,7 @@ def quaternion_matrix(quaternion: numpy.ndarray) -> numpy.ndarray: 143 True 144 145 """ 146- q = numpy.array(quaternion, dtype=numpy.float64, copy=True) 147+ q = numpy.asarray(quaternion, dtype=numpy.float64, copy=True) 148 n = numpy.dot(q, q) 149 if n < _EPS: 150 return numpy.identity(4) 151@@ -1379,7 +1379,7 @@ def quaternion_from_matrix( 152 True 153 154 """ 155- M = numpy.array(matrix, dtype=numpy.float64, copy=False)[:4, :4] 156+ M = numpy.asarray(matrix, dtype=numpy.float64)[:4, :4] 157 if isprecise: 158 q = numpy.empty((4,)) 159 t = numpy.trace(M) 160@@ -1460,7 +1460,7 @@ def quaternion_conjugate(quaternion: numpy.ndarray) -> numpy.ndarray: 161 True 162 163 """ 164- q = numpy.array(quaternion, dtype=numpy.float64, copy=True) 165+ q = numpy.asarray(quaternion, dtype=numpy.float64, copy=True) 166 numpy.negative(q[1:], q[1:]) 167 return q 168 169@@ -1474,7 +1474,7 @@ def quaternion_inverse(quaternion: numpy.ndarray) -> numpy.ndarray: 170 True 171 172 """ 173- q = numpy.array(quaternion, dtype=numpy.float64, copy=True) 174+ q = numpy.asarray(quaternion, dtype=numpy.float64, copy=True) 175 numpy.negative(q[1:], q[1:]) 176 return q / numpy.dot(q, q) 177 178@@ -1496,7 +1496,7 @@ def quaternion_imag(quaternion: numpy.ndarray) -> numpy.ndarray: 179 array([ 0., 1., 2.]) 180 181 """ 182- return numpy.array(quaternion[1:4], dtype=numpy.float64, copy=True) 183+ return numpy.asarray(quaternion[1:4], dtype=numpy.float64, copy=True) 184 185 186 def quaternion_slerp( 187@@ -1654,7 +1654,7 @@ def vector_norm( 188 1.0 189 190 """ 191- data = numpy.array(data, dtype=numpy.float64, copy=True) 192+ data = numpy.asarray(data, dtype=numpy.float64, copy=True) 193 if out is None: 194 if data.ndim == 1: 195 return math.sqrt(numpy.dot(data, data)) 196@@ -1697,13 +1697,13 @@ def unit_vector( 197 198 """ 199 if out is None: 200- data = numpy.array(data, dtype=numpy.float64, copy=True) 201+ data = numpy.asarray(data, dtype=numpy.float64, copy=True) 202 if data.ndim == 1: 203 data /= math.sqrt(numpy.dot(data, data)) 204 return data 205 else: 206 if out is not data: 207- out[:] = numpy.array(data, copy=False) 208+ out[:] = numpy.asarray(data) 209 data = out 210 length = numpy.atleast_1d(numpy.sum(data * data, axis)) 211 numpy.sqrt(length, length) 212@@ -1777,8 +1777,8 @@ def angle_between_vectors( 213 True 214 215 """ 216- v0 = numpy.array(v0, dtype=numpy.float64, copy=False) 217- v1 = numpy.array(v1, dtype=numpy.float64, copy=False) 218+ v0 = numpy.asarray(v0, dtype=numpy.float64) 219+ v1 = numpy.asarray(v1, dtype=numpy.float64) 220 dot = numpy.sum(v0 * v1, axis=axis) 221 dot /= vector_norm(v0, axis=axis) * vector_norm(v1, axis=axis) 222 dot = numpy.clip(dot, -1.0, 1.0) 223@@ -1826,9 +1826,9 @@ def is_same_transform(matrix0: numpy.ndarray, matrix1: numpy.ndarray) -> numpy.n 224 False 225 226 """ 227- matrix0 = numpy.array(matrix0, dtype=numpy.float64, copy=True) 228+ matrix0 = numpy.asarray(matrix0, dtype=numpy.float64, copy=True) 229 matrix0 /= matrix0[3, 3] 230- matrix1 = numpy.array(matrix1, dtype=numpy.float64, copy=True) 231+ matrix1 = numpy.asarray(matrix1, dtype=numpy.float64, copy=True) 232 matrix1 /= matrix1[3, 3] 233 return numpy.allclose(matrix0, matrix1) 234 235@@ -1874,3 +1874,4 @@ if __name__ == "__main__": 236 237 numpy.set_printoptions(suppress=True, precision=5) 238 doctest.testmod() 239+