Browse Source

Merge pull request #3229 from AleksandrPanov:add_Dictionary_bindings

* add Dictionary bindings

* add python tests
pull/3244/head
Alexander Panov 3 years ago committed by GitHub
parent
commit
f6a39c5d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      modules/aruco/include/opencv2/aruco/dictionary.hpp
  2. 20
      modules/aruco/misc/python/test/test_aruco.py

4
modules/aruco/include/opencv2/aruco/dictionary.hpp

@ -117,13 +117,13 @@ class CV_EXPORTS_W Dictionary { @@ -117,13 +117,13 @@ class CV_EXPORTS_W Dictionary {
* @brief Given a matrix of bits. Returns whether if marker is identified or not.
* It returns by reference the correct id (if any) and the correct rotation
*/
bool identify(const Mat &onlyBits, int &idx, int &rotation, double maxCorrectionRate) const;
CV_WRAP bool identify(const Mat &onlyBits, CV_OUT int &idx, CV_OUT int &rotation, double maxCorrectionRate) const;
/**
* @brief Returns the distance of the input bits to the specific id. If allRotations is true,
* the four posible bits rotation are considered
*/
int getDistanceToId(InputArray bits, int id, bool allRotations = true) const;
CV_WRAP int getDistanceToId(InputArray bits, int id, bool allRotations = true) const;
/**

20
modules/aruco/misc/python/test/test_aruco.py

@ -64,6 +64,26 @@ class aruco_test(NewOpenCVTests): @@ -64,6 +64,26 @@ class aruco_test(NewOpenCVTests):
if os.path.exists(filename):
os.remove(filename)
def test_identify(self):
aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_50)
expected_idx = 9
expected_rotation = 2
bit_marker = np.array([[0, 1, 1, 0], [1, 0, 1, 0], [1, 1, 1, 1], [0, 0, 1, 1]], dtype=np.uint8)
check, idx, rotation = aruco_dict.identify(bit_marker, 0)
self.assertTrue(check, True)
self.assertEqual(idx, expected_idx)
self.assertEqual(rotation, expected_rotation)
def test_getDistanceToId(self):
aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_50)
idx = 7
rotation = 3
bit_marker = np.array([[0, 1, 0, 1], [0, 1, 1, 1], [1, 1, 0, 0], [0, 1, 0, 0]], dtype=np.uint8)
dist = aruco_dict.getDistanceToId(bit_marker, idx)
self.assertEqual(dist, 0)
if __name__ == '__main__':
NewOpenCVTests.bootstrap()

Loading…
Cancel
Save