Loading autocnet/transformation/fundamental_matrix.py +5 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,9 @@ def compute_reprojection_error(F, x, x1, index=None): if x1.shape[1] != 3: x1 = make_homogeneous(x1) if isinstance(x, (pd.Series, pd.DataFrame)): x = x.values if isinstance(x1, (pd.Series, pd.DataFrame)): x1 = x1.values # Normalize the vector Loading @@ -56,7 +58,7 @@ def compute_reprojection_error(F, x, x1, index=None): dist2 = np.sum(l2.conj() * x.T, axis=0) F_error = np.sqrt(dist1**2 + dist2**2) if index: if index is not None: F_error = pd.Series(F_error, index=index) return F_error Loading @@ -64,6 +66,8 @@ def compute_reprojection_error(F, x, x1, index=None): l_norms = normalize_vector(x.dot(F.T)) F_error = np.abs(np.sum(l_norms * x1, axis=1)) if index: F_error = pd.Series(F_error, index=index) return F_error def compute_fundamental_error(F, x, x1): Loading autocnet/transformation/tests/test_fundamental_matrix.py +10 −1 Original line number Diff line number Diff line Loading @@ -86,6 +86,15 @@ class TestFundamentalMatrix(unittest.TestCase): self.fixed_x2) self.assertTrue(err.mean() < 0.5) def test_f_reprojection_error_pd(self): index = np.arange(10)[::-1] err = fm.compute_reprojection_error(self.fixed_f, self.fixed_x1, self.fixed_x2, index=index) self.assertIsInstance(err, pd.Series) np.testing.assert_array_equal(err.index, index) def test_f_fundamental_error(self): err = fm.compute_fundamental_error(self.fixed_f, self.fixed_x1, Loading @@ -101,7 +110,7 @@ class TestFundamentalMatrix(unittest.TestCase): F, mask = fm.compute_fundamental_matrix(fp, tp, method='ransac') new_mask = fm.update_fundamental_mask(F, fp, tp, threshold=0.5, method='reprojection') self.assertEqual(10, new_mask['fundamental'].sum()) self.assertEqual(8, new_mask['fundamental'].sum()) def test_update_fundamental_mask_with_index(self): np.random.seed(12345) Loading autocnet/utils/tests/test_utils.py +0 −10 Original line number Diff line number Diff line Loading @@ -110,16 +110,6 @@ class TestUtils(unittest.TestCase): cleaned_array = utils.remove_field_name(starray, 'index') np.testing.assert_array_equal(cleaned_array, truth) def test_normalize_vector(self): x = np.array([1,1,1], dtype=np.float) y = utils.normalize_vector(x) np.testing.assert_array_almost_equal(np.array([ 0.70710678, 0.70710678, 0.70710678]), y) x = np.repeat(np.arange(1,5), 3).reshape(-1, 3) y = utils.normalize_vector(x) truth = np.tile(np.array([ 0.70710678, 0.70710678, 0.70710678]), 4).reshape(4,3) np.testing.assert_array_almost_equal(truth, y) def test_slope(self): x1 = pd.DataFrame({'x': np.arange(1, 11), 'y': np.arange(1, 11)}) Loading autocnet/utils/utils.py +4 −8 Original line number Diff line number Diff line Loading @@ -42,18 +42,14 @@ def normalize_vector(line): Examples -------- >>> x = np.random.random((3,3)) >>> x = np.array([3, 1, 2]) >>> normalize_vector(x) array([[ 0.88280225, 0.4697448 , 0.11460811], [ 0.26090555, 0.96536433, 0.91648305], [ 0.58271501, 0.81267657, 0.30796395]]) array([ 0.80178373, 0.26726124, 0.53452248]) """ if isinstance(line, pd.DataFrame): line = line.values n = line[0]**2 + line[1]**2 + line[2]**2 line /= np.sqrt(n) return line n = np.sqrt((line[0]**2 + line[1]**2 + line[2]**2)) return line / abs(n) def getnearest(iterable, value): """ Loading Loading
autocnet/transformation/fundamental_matrix.py +5 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,9 @@ def compute_reprojection_error(F, x, x1, index=None): if x1.shape[1] != 3: x1 = make_homogeneous(x1) if isinstance(x, (pd.Series, pd.DataFrame)): x = x.values if isinstance(x1, (pd.Series, pd.DataFrame)): x1 = x1.values # Normalize the vector Loading @@ -56,7 +58,7 @@ def compute_reprojection_error(F, x, x1, index=None): dist2 = np.sum(l2.conj() * x.T, axis=0) F_error = np.sqrt(dist1**2 + dist2**2) if index: if index is not None: F_error = pd.Series(F_error, index=index) return F_error Loading @@ -64,6 +66,8 @@ def compute_reprojection_error(F, x, x1, index=None): l_norms = normalize_vector(x.dot(F.T)) F_error = np.abs(np.sum(l_norms * x1, axis=1)) if index: F_error = pd.Series(F_error, index=index) return F_error def compute_fundamental_error(F, x, x1): Loading
autocnet/transformation/tests/test_fundamental_matrix.py +10 −1 Original line number Diff line number Diff line Loading @@ -86,6 +86,15 @@ class TestFundamentalMatrix(unittest.TestCase): self.fixed_x2) self.assertTrue(err.mean() < 0.5) def test_f_reprojection_error_pd(self): index = np.arange(10)[::-1] err = fm.compute_reprojection_error(self.fixed_f, self.fixed_x1, self.fixed_x2, index=index) self.assertIsInstance(err, pd.Series) np.testing.assert_array_equal(err.index, index) def test_f_fundamental_error(self): err = fm.compute_fundamental_error(self.fixed_f, self.fixed_x1, Loading @@ -101,7 +110,7 @@ class TestFundamentalMatrix(unittest.TestCase): F, mask = fm.compute_fundamental_matrix(fp, tp, method='ransac') new_mask = fm.update_fundamental_mask(F, fp, tp, threshold=0.5, method='reprojection') self.assertEqual(10, new_mask['fundamental'].sum()) self.assertEqual(8, new_mask['fundamental'].sum()) def test_update_fundamental_mask_with_index(self): np.random.seed(12345) Loading
autocnet/utils/tests/test_utils.py +0 −10 Original line number Diff line number Diff line Loading @@ -110,16 +110,6 @@ class TestUtils(unittest.TestCase): cleaned_array = utils.remove_field_name(starray, 'index') np.testing.assert_array_equal(cleaned_array, truth) def test_normalize_vector(self): x = np.array([1,1,1], dtype=np.float) y = utils.normalize_vector(x) np.testing.assert_array_almost_equal(np.array([ 0.70710678, 0.70710678, 0.70710678]), y) x = np.repeat(np.arange(1,5), 3).reshape(-1, 3) y = utils.normalize_vector(x) truth = np.tile(np.array([ 0.70710678, 0.70710678, 0.70710678]), 4).reshape(4,3) np.testing.assert_array_almost_equal(truth, y) def test_slope(self): x1 = pd.DataFrame({'x': np.arange(1, 11), 'y': np.arange(1, 11)}) Loading
autocnet/utils/utils.py +4 −8 Original line number Diff line number Diff line Loading @@ -42,18 +42,14 @@ def normalize_vector(line): Examples -------- >>> x = np.random.random((3,3)) >>> x = np.array([3, 1, 2]) >>> normalize_vector(x) array([[ 0.88280225, 0.4697448 , 0.11460811], [ 0.26090555, 0.96536433, 0.91648305], [ 0.58271501, 0.81267657, 0.30796395]]) array([ 0.80178373, 0.26726124, 0.53452248]) """ if isinstance(line, pd.DataFrame): line = line.values n = line[0]**2 + line[1]**2 + line[2]**2 line /= np.sqrt(n) return line n = np.sqrt((line[0]**2 + line[1]**2 + line[2]**2)) return line / abs(n) def getnearest(iterable, value): """ Loading