Skip to content

Commit 7e7fbba

Browse files
committed
add setIds and make ids field RW in python
1 parent 4613c51 commit 7e7fbba

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

modules/aruco/include/opencv2/aruco.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,18 @@ class CV_EXPORTS_W Board {
281281
*
282282
*/
283283
CV_WRAP static Ptr<Board> create(InputArrayOfArrays objPoints, const Ptr<Dictionary> &dictionary, InputArray ids);
284+
285+
/**
286+
* @brief Set ids vector
287+
*
288+
* @param ids vector of the identifiers of the markers in the board (should be the same size
289+
* as objPoints)
290+
*
291+
* Recommended way to set ids vector, which will fail if the size of ids does not match size
292+
* of objPoints.
293+
*/
294+
CV_WRAP void setIds(InputArray ids);
295+
284296
/// array of object points of all the marker corners in the board
285297
/// each marker include its 4 corners in CCW order. For M markers, the size is Mx4.
286298
CV_PROP std::vector< std::vector< Point3f > > objPoints;
@@ -290,7 +302,7 @@ class CV_EXPORTS_W Board {
290302

291303
/// vector of the identifiers of the markers in the board (same size than objPoints)
292304
/// The identifiers refers to the board dictionary
293-
CV_PROP std::vector< int > ids;
305+
CV_PROP_RW std::vector< int > ids;
294306
};
295307

296308

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
3+
# Python 2/3 compatibility
4+
from __future__ import print_function
5+
6+
import os, numpy as np
7+
8+
import cv2 as cv
9+
10+
from tests_common import NewOpenCVTests
11+
12+
class aruco_test(NewOpenCVTests):
13+
14+
def test_idsAccessibility(self):
15+
16+
ids = np.array([[elem] for elem in range(17)])
17+
rev_ids = np.array(list(reversed(ids)))
18+
19+
aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_5X5_250)
20+
board = cv.aruco.CharucoBoard_create(7, 5, 1, 0.5, aruco_dict)
21+
22+
self.assertTrue(np.equal(board.ids, ids).all())
23+
24+
board.ids = rev_ids
25+
self.assertTrue(np.equal(board.ids, rev_ids).all())
26+
27+
board.setIds(ids)
28+
self.assertTrue(np.equal(board.ids, ids).all())
29+
30+
with self.assertRaises(cv.error):
31+
board.setIds(np.array([0]))
32+
33+
if __name__ == '__main__':
34+
NewOpenCVTests.bootstrap()

modules/aruco/src/aruco.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,13 @@ Ptr<Board> Board::create(InputArrayOfArrays objPoints, const Ptr<Dictionary> &di
16591659
return res;
16601660
}
16611661

1662+
/**
1663+
*/
1664+
void Board::setIds(InputArray ids_) {
1665+
CV_Assert(objPoints.size() == ids_.total());
1666+
ids_.copyTo(this->ids);
1667+
}
1668+
16621669
/**
16631670
*/
16641671
Ptr<GridBoard> GridBoard::create(int markersX, int markersY, float markerLength, float markerSeparation,

0 commit comments

Comments
 (0)