@@ -22,17 +22,17 @@ static void _drawPlanarBoardImpl(Board *_board, Size outSize, OutputArray _img,
22
22
out.adjustROI (-marginSize, -marginSize, -marginSize, -marginSize);
23
23
24
24
// calculate max and min values in XY plane
25
- CV_Assert (_board->objPoints .size () > 0 );
25
+ CV_Assert (_board->getObjPoints () .size () > 0 );
26
26
float minX, maxX, minY, maxY;
27
- minX = maxX = _board->objPoints [0 ][0 ].x ;
28
- minY = maxY = _board->objPoints [0 ][0 ].y ;
27
+ minX = maxX = _board->getObjPoints () [0 ][0 ].x ;
28
+ minY = maxY = _board->getObjPoints () [0 ][0 ].y ;
29
29
30
- for (unsigned int i = 0 ; i < _board->objPoints .size (); i++) {
30
+ for (unsigned int i = 0 ; i < _board->getObjPoints () .size (); i++) {
31
31
for (int j = 0 ; j < 4 ; j++) {
32
- minX = min (minX, _board->objPoints [i][j].x );
33
- maxX = max (maxX, _board->objPoints [i][j].x );
34
- minY = min (minY, _board->objPoints [i][j].y );
35
- maxY = max (maxY, _board->objPoints [i][j].y );
32
+ minX = min (minX, _board->getObjPoints () [i][j].x );
33
+ maxX = max (maxX, _board->getObjPoints () [i][j].x );
34
+ minY = min (minY, _board->getObjPoints () [i][j].y );
35
+ maxY = max (maxY, _board->getObjPoints () [i][j].y );
36
36
}
37
37
}
38
38
@@ -55,14 +55,14 @@ static void _drawPlanarBoardImpl(Board *_board, Size outSize, OutputArray _img,
55
55
}
56
56
57
57
// now paint each marker
58
- Dictionary &dictionary = *(_board->dictionary );
58
+ Dictionary &dictionary = *(_board->getDictionary () );
59
59
Mat marker;
60
60
Point2f outCorners[3 ];
61
61
Point2f inCorners[3 ];
62
- for (unsigned int m = 0 ; m < _board->objPoints .size (); m++) {
62
+ for (unsigned int m = 0 ; m < _board->getObjPoints () .size (); m++) {
63
63
// transform corners to markerZone coordinates
64
64
for (int j = 0 ; j < 3 ; j++) {
65
- Point2f pf = Point2f (_board->objPoints [m][j].x , _board->objPoints [m][j].y );
65
+ Point2f pf = Point2f (_board->getObjPoints () [m][j].x , _board->getObjPoints () [m][j].y );
66
66
// move top left to 0, 0
67
67
pf -= Point2f (minX, minY);
68
68
pf.x = pf.x / sizeX * float (out.cols );
@@ -73,7 +73,7 @@ static void _drawPlanarBoardImpl(Board *_board, Size outSize, OutputArray _img,
73
73
// get marker
74
74
Size dst_sz (outCorners[2 ] - outCorners[0 ]); // assuming CCW order
75
75
dst_sz.width = dst_sz.height = std::min (dst_sz.width , dst_sz.height ); // marker should be square
76
- dictionary.drawMarker (_board->ids [m], dst_sz.width , marker, borderBits);
76
+ dictionary.drawMarker (_board->getIds () [m], dst_sz.width , marker, borderBits);
77
77
78
78
if ((outCorners[0 ].y == outCorners[1 ].y ) && (outCorners[1 ].x == outCorners[2 ].x )) {
79
79
// marker is aligned to image axes
@@ -150,6 +150,46 @@ void Board::setIds(InputArray ids_) {
150
150
ids_.copyTo (this ->ids );
151
151
}
152
152
153
+ Ptr <Dictionary> Board::getDictionary () const {
154
+ return this ->dictionary ;
155
+ }
156
+
157
+ void Board::setDictionary (const Ptr <Dictionary> &_dictionary) {
158
+ this ->dictionary = _dictionary;
159
+ }
160
+
161
+ const std::vector<std::vector<Point3f> >& Board::getObjPoints () const {
162
+ return this ->objPoints ;
163
+ }
164
+
165
+ void Board::setObjPoints (const vector<std::vector<Point3f>> &_objPoints) {
166
+ CV_Assert (!_objPoints.empty ());
167
+ this ->objPoints = _objPoints;
168
+ rightBottomBorder = _objPoints.front ().front ();
169
+ for (size_t i = 0 ; i < this ->objPoints .size (); i++) {
170
+ for (int j = 0 ; j < 4 ; j++) {
171
+ const Point3f &corner = this ->objPoints [i][j];
172
+ rightBottomBorder.x = std::max (rightBottomBorder.x , corner.x );
173
+ rightBottomBorder.y = std::max (rightBottomBorder.y , corner.y );
174
+ rightBottomBorder.z = std::max (rightBottomBorder.z , corner.z );
175
+ }
176
+ }
177
+ }
178
+
179
+ const Point3f& Board::getRightBottomBorder () const {
180
+ return this ->rightBottomBorder ;
181
+ }
182
+
183
+ const std::vector<int >& Board::getIds () const {
184
+ return this ->ids ;
185
+ }
186
+
187
+ void Board::changeId (int index, int newId) {
188
+ CV_Assert (index >= 0 && index < (int )ids.size ());
189
+ CV_Assert (newId >= 0 && newId < dictionary->bytesList .rows );
190
+ this ->ids [index ] = newId;
191
+ }
192
+
153
193
Ptr <GridBoard> GridBoard::create (int markersX, int markersY, float markerLength, float markerSeparation,
154
194
const Ptr <Dictionary> &dictionary, int firstMarker) {
155
195
CV_Assert (markersX > 0 && markersY > 0 && markerLength > 0 && markerSeparation > 0 );
@@ -158,11 +198,12 @@ Ptr<GridBoard> GridBoard::create(int markersX, int markersY, float markerLength,
158
198
res->gridImpl ->sizeY = markersY;
159
199
res->gridImpl ->markerLength = markerLength;
160
200
res->gridImpl ->markerSeparation = markerSeparation;
161
- res->dictionary = dictionary ;
201
+ res->setDictionary ( dictionary) ;
162
202
163
203
size_t totalMarkers = (size_t ) markersX * markersY;
164
204
res->ids .resize (totalMarkers);
165
- res->objPoints .reserve (totalMarkers);
205
+ std::vector<std::vector<Point3f> > objPoints;
206
+ objPoints.reserve (totalMarkers);
166
207
167
208
// fill ids with first identifiers
168
209
for (unsigned int i = 0 ; i < totalMarkers; i++) {
@@ -178,9 +219,10 @@ Ptr<GridBoard> GridBoard::create(int markersX, int markersY, float markerLength,
178
219
corners[1 ] = corners[0 ] + Point3f (markerLength, 0 , 0 );
179
220
corners[2 ] = corners[0 ] + Point3f (markerLength, markerLength, 0 );
180
221
corners[3 ] = corners[0 ] + Point3f (0 , markerLength, 0 );
181
- res-> objPoints .push_back (corners);
222
+ objPoints.push_back (corners);
182
223
}
183
224
}
225
+ res->setObjPoints (objPoints);
184
226
res->rightBottomBorder = Point3f (markersX * markerLength + markerSeparation * (markersX - 1 ),
185
227
markersY * markerLength + markerSeparation * (markersY - 1 ), 0 .f );
186
228
return res;
@@ -281,7 +323,7 @@ static inline void _getNearestMarkerCorners(CharucoBoard &board, float squareLen
281
323
board.nearestMarkerIdx .resize (board.chessboardCorners .size ());
282
324
board.nearestMarkerCorners .resize (board.chessboardCorners .size ());
283
325
284
- unsigned int nMarkers = (unsigned int )board.ids .size ();
326
+ unsigned int nMarkers = (unsigned int )board.getIds () .size ();
285
327
unsigned int nCharucoCorners = (unsigned int )board.chessboardCorners .size ();
286
328
for (unsigned int i = 0 ; i < nCharucoCorners; i++) {
287
329
double minDist = -1 ; // distance of closest markers
@@ -290,7 +332,7 @@ static inline void _getNearestMarkerCorners(CharucoBoard &board, float squareLen
290
332
// calculate distance from marker center to charuco corner
291
333
Point3f center = Point3f (0 , 0 , 0 );
292
334
for (unsigned int k = 0 ; k < 4 ; k++)
293
- center += board.objPoints [j][k];
335
+ center += board.getObjPoints () [j][k];
294
336
center /= 4 .;
295
337
double sqDistance;
296
338
Point3f distVector = charucoCorner - center;
@@ -313,7 +355,7 @@ static inline void _getNearestMarkerCorners(CharucoBoard &board, float squareLen
313
355
double minDistCorner = -1 ;
314
356
for (unsigned int k = 0 ; k < 4 ; k++) {
315
357
double sqDistance;
316
- Point3f distVector = charucoCorner - board.objPoints [board.nearestMarkerIdx [i][j]][k];
358
+ Point3f distVector = charucoCorner - board.getObjPoints () [board.nearestMarkerIdx [i][j]][k];
317
359
sqDistance = distVector.x * distVector.x + distVector.y * distVector.y ;
318
360
if (k == 0 || sqDistance < minDistCorner) {
319
361
// if this corner is closer to the charuco corner, assing its index
@@ -335,7 +377,8 @@ Ptr<CharucoBoard> CharucoBoard::create(int squaresX, int squaresY, float squareL
335
377
res->charucoImpl ->sizeY = squaresY;
336
378
res->charucoImpl ->squareLength = squareLength;
337
379
res->charucoImpl ->markerLength = markerLength;
338
- res->dictionary = dictionary;
380
+ res->setDictionary (dictionary);
381
+ std::vector<std::vector<Point3f> > objPoints;
339
382
340
383
float diffSquareMarkerLength = (squareLength - markerLength) / 2 ;
341
384
// calculate Board objPoints
@@ -350,12 +393,13 @@ Ptr<CharucoBoard> CharucoBoard::create(int squaresX, int squaresY, float squareL
350
393
corners[1 ] = corners[0 ] + Point3f (markerLength, 0 , 0 );
351
394
corners[2 ] = corners[0 ] + Point3f (markerLength, markerLength, 0 );
352
395
corners[3 ] = corners[0 ] + Point3f (0 , markerLength, 0 );
353
- res-> objPoints .push_back (corners);
396
+ objPoints.push_back (corners);
354
397
// first ids in dictionary
355
398
int nextId = (int )res->ids .size ();
356
399
res->ids .push_back (nextId);
357
400
}
358
401
}
402
+ res->setObjPoints (objPoints);
359
403
360
404
// now fill chessboardCorners
361
405
for (int y = 0 ; y < squaresY - 1 ; y++) {
0 commit comments