Skip to content

Commit f6a39c5

Browse files
author
Alexander Panov
authored
Merge pull request #3229 from AleksandrPanov:add_Dictionary_bindings
* add Dictionary bindings * add python tests
1 parent b8e4061 commit f6a39c5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ class CV_EXPORTS_W Dictionary {
117117
* @brief Given a matrix of bits. Returns whether if marker is identified or not.
118118
* It returns by reference the correct id (if any) and the correct rotation
119119
*/
120-
bool identify(const Mat &onlyBits, int &idx, int &rotation, double maxCorrectionRate) const;
120+
CV_WRAP bool identify(const Mat &onlyBits, CV_OUT int &idx, CV_OUT int &rotation, double maxCorrectionRate) const;
121121

122122
/**
123123
* @brief Returns the distance of the input bits to the specific id. If allRotations is true,
124124
* the four posible bits rotation are considered
125125
*/
126-
int getDistanceToId(InputArray bits, int id, bool allRotations = true) const;
126+
CV_WRAP int getDistanceToId(InputArray bits, int id, bool allRotations = true) const;
127127

128128

129129
/**

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ def test_write_read_dict(self):
6464
if os.path.exists(filename):
6565
os.remove(filename)
6666

67+
def test_identify(self):
68+
aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_50)
69+
expected_idx = 9
70+
expected_rotation = 2
71+
bit_marker = np.array([[0, 1, 1, 0], [1, 0, 1, 0], [1, 1, 1, 1], [0, 0, 1, 1]], dtype=np.uint8)
72+
73+
check, idx, rotation = aruco_dict.identify(bit_marker, 0)
74+
75+
self.assertTrue(check, True)
76+
self.assertEqual(idx, expected_idx)
77+
self.assertEqual(rotation, expected_rotation)
78+
79+
def test_getDistanceToId(self):
80+
aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_50)
81+
idx = 7
82+
rotation = 3
83+
bit_marker = np.array([[0, 1, 0, 1], [0, 1, 1, 1], [1, 1, 0, 0], [0, 1, 0, 0]], dtype=np.uint8)
84+
dist = aruco_dict.getDistanceToId(bit_marker, idx)
85+
86+
self.assertEqual(dist, 0)
6787

6888
if __name__ == '__main__':
6989
NewOpenCVTests.bootstrap()

0 commit comments

Comments
 (0)