test_matcher.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import unittest
  2. import os
  3. import sys
  4. import numpy as np
  5. sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
  6. '..', '..')))
  7. from opencv_stitching.feature_matcher import FeatureMatcher
  8. # %%
  9. class TestMatcher(unittest.TestCase):
  10. def test_array_in_sqare_matrix(self):
  11. array = np.zeros(9)
  12. matrix = FeatureMatcher.array_in_sqare_matrix(array)
  13. np.testing.assert_array_equal(matrix, np.array([[0., 0., 0.],
  14. [0., 0., 0.],
  15. [0., 0., 0.]]))
  16. def test_get_all_img_combinations(self):
  17. nimgs = 3
  18. combinations = list(FeatureMatcher.get_all_img_combinations(nimgs))
  19. self.assertEqual(combinations, [(0, 1), (0, 2), (1, 2)])
  20. def test_get_match_conf(self):
  21. explicit_match_conf = FeatureMatcher.get_match_conf(1, 'orb')
  22. implicit_match_conf_orb = FeatureMatcher.get_match_conf(None, 'orb')
  23. implicit_match_conf_other = FeatureMatcher.get_match_conf(None, 'surf')
  24. self.assertEqual(explicit_match_conf, 1)
  25. self.assertEqual(implicit_match_conf_orb, 0.3)
  26. self.assertEqual(implicit_match_conf_other, 0.65)
  27. def starttest():
  28. unittest.main()
  29. if __name__ == "__main__":
  30. starttest()