Skip to content

Commit ebc255b

Browse files
committed
fixed sample code in tutorial
1 parent 9a3cb30 commit ebc255b

File tree

5 files changed

+68
-67
lines changed

5 files changed

+68
-67
lines changed

modules/aruco/tutorials/aruco_board_detection/aruco_board_detection.markdown

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The aruco module allows the use of Boards. The main class is the ```cv::aruco::B
3030
class Board {
3131
public:
3232
std::vector<std::vector<cv::Point3f> > objPoints;
33-
cv::aruco::Dictionary dictionary;
33+
cv::Ptr<cv::aruco::Dictionary> dictionary;
3434
std::vector<int> ids;
3535
};
3636
```
@@ -57,10 +57,10 @@ The aruco module provides a specific function, ```estimatePoseBoard()```, to per
5757
cv::Mat cameraMatrix, distCoeffs;
5858
readCameraParameters(cameraMatrix, distCoeffs);
5959
// assume we have a function to create the board object
60-
cv::aruco::Board board = createBoard();
60+
cv::Ptr<cv::aruco::Board> board = cv::aruco::Board::create();
6161
...
62-
vector< int > markerIds;
63-
vector< vector<Point2f> > markerCorners;
62+
std::vector<int> markerIds;
63+
std::vector<std::vector<cv::Point2f>> markerCorners;
6464
cv::aruco::detectMarkers(inputImage, board.dictionary, markerCorners, markerIds);
6565
// if at least one marker detected
6666
if(markerIds.size() > 0) {
@@ -137,9 +137,9 @@ After creating a Grid Board, we probably want to print it and use it. A function
137137
of a ```GridBoard``` is provided in ```cv::aruco::GridBoard::draw()```. For example:
138138

139139
``` c++
140-
cv::aruco::GridBoard board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
140+
cv::Ptr<cv::aruco::GridBoard> board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
141141
cv::Mat boardImage;
142-
board.draw( cv::Size(600, 500), boardImage, 10, 1 );
142+
board->draw( cv::Size(600, 500), boardImage, 10, 1 );
143143
```
144144
145145
- The first parameter is the size of the output image in pixels. In this case 600x500 pixels. If this is not proportional
@@ -170,8 +170,8 @@ Finally, a full example of board detection:
170170
// camera parameters are read from somewhere
171171
readCameraParameters(cameraMatrix, distCoeffs);
172172

173-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
174-
cv::aruco::GridBoard board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
173+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
174+
cv::Ptr<cv::aruco::GridBoard> board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
175175

176176
while (inputVideo.grab()) {
177177
cv::Mat image, imageCopy;
@@ -256,10 +256,10 @@ internal bits are not analyzed at all and only the corner distances are evaluate
256256
This is an example of using the ```refineDetectedMarkers()``` function:
257257

258258
``` c++
259-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
260-
cv::aruco::GridBoard board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
261-
vector< int > markerIds;
262-
vector< vector<Point2f> > markerCorners, rejectedCandidates;
259+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
260+
cv::Ptr<cv::aruco::GridBoard> board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary);
261+
std::vector<int> markerIds;
262+
std::vector<std::vector<cv::Point2f>> markerCorners, rejectedCandidates;
263263
cv::aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, cv::aruco::DetectorParameters(), rejectedCandidates);
264264

265265
cv::aruco::refineDetectedMarkersinputImage, board, markerCorners, markerIds, rejectedCandidates);

modules/aruco/tutorials/aruco_calibration/aruco_calibration.markdown

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ visible in all the viewpoints.
3333
The function to calibrate is ```calibrateCameraCharuco()```. Example:
3434

3535
``` c++
36-
aruco::CharucoBoard board = ... // create charuco board
36+
cv::Ptr<aruco::CharucoBoard> board = ... // create charuco board
3737
cv::Size imgSize = ... // camera image size
3838

39-
std::vector< std::vector<cv::Point2f> > allCharucoCorners;
40-
std::vector< std::vector<int> > allCharucoIds;
39+
std::vector<std::vector<cv::Point2f>> allCharucoCorners;
40+
std::vector<std::vector<int>> allCharucoIds;
4141
// Detect charuco board from several viewpoints and fill allCharucoCorners and allCharucoIds
4242
...
4343
...
4444

4545
// After capturing in several viewpoints, start calibration
4646
cv::Mat cameraMatrix, distCoeffs;
47-
std::vector< Mat > rvecs, tvecs;
47+
std::vector<cv::Mat> rvecs, tvecs;
4848
int calibrationFlags = ... // Set calibration flags (same than in calibrateCamera() function)
4949

5050
double repError = cv::aruco::calibrateCameraCharuco(allCharucoCorners, allCharucoIds, board, imgSize, cameraMatrix, distCoeffs, rvecs, tvecs, calibrationFlags);
@@ -81,19 +81,19 @@ requires the detections of an ArUco board from different viewpoints.
8181
Example of ```calibrateCameraAruco()``` use:
8282
8383
``` c++
84-
aruco::Board board = ... // create aruco board
84+
cv::Ptr<aruco::Board> board = ... // create aruco board
8585
cv::Size imgSize = ... // camera image size
8686
87-
std::vector< std::vector< cv::Point2f > > allCornersConcatenated;
88-
std::vector< int > allIdsConcatenated;
89-
std::vector< int > markerCounterPerFrame;
87+
std::vector<std::vector<cv::Point2f>> allCornersConcatenated;
88+
std::vector<int> allIdsConcatenated;
89+
std::vector<int> markerCounterPerFrame;
9090
// Detect aruco board from several viewpoints and fill allCornersConcatenated, allIdsConcatenated and markerCounterPerFrame
9191
...
9292
...
9393
9494
// After capturing in several viewpoints, start calibration
9595
cv::Mat cameraMatrix, distCoeffs;
96-
std::vector< Mat > rvecs, tvecs;
96+
std::vector<cv::Mat> rvecs, tvecs;
9797
int calibrationFlags = ... // Set calibration flags (same than in calibrateCamera() function)
9898
9999
double repError = cv::aruco::calibrateCameraAruco(allCornersConcatenated, allIdsConcatenated, markerCounterPerFrame, board, imgSize, cameraMatrix, distCoeffs, rvecs, tvecs, calibrationFlags);

modules/aruco/tutorials/aruco_detection/aruco_detection.markdown

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ For example, lets analyze the following call:
7171

7272
``` c++
7373
cv::Mat markerImage;
74-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
74+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
7575
cv::aruco::drawMarker(dictionary, 23, 200, markerImage, 1);
7676
```
7777
@@ -156,10 +156,10 @@ An example of marker detection:
156156
``` c++
157157
cv::Mat inputImage;
158158
...
159-
vector< int > markerIds;
160-
vector< vector<Point2f> > markerCorners, rejectedCandidates;
161-
cv::aruco::DetectorParameters parameters;
162-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
159+
std::vector<int> markerIds;
160+
std::vector<std::vector<cv::Point2f>> markerCorners, rejectedCandidates;
161+
cv::Ptr<cv::aruco::DetectorParameters> parameters;
162+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
163163
cv::aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, parameters, rejectedCandidates);
164164
```
165165
@@ -204,7 +204,7 @@ camera:
204204
``` c++
205205
cv::VideoCapture inputVideo;
206206
inputVideo.open(0);
207-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
207+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
208208
while (inputVideo.grab()) {
209209
cv::Mat image, imageCopy;
210210
inputVideo.retrieve(image);
@@ -263,9 +263,9 @@ information).
263263
The aruco module provides a function to estimate the poses of all the detected markers:
264264

265265
``` c++
266-
Mat cameraMatrix, distCoeffs;
266+
cv::Mat cameraMatrix, distCoeffs;
267267
...
268-
vector< Vec3d > rvecs, tvecs;
268+
std::vector<cv::Vec3d> rvecs, tvecs;
269269
cv::aruco::estimatePoseSingleMarkers(corners, 0.05, cameraMatrix, distCoeffs, rvecs, tvecs);
270270
```
271271
@@ -303,22 +303,22 @@ A basic full example for pose estimation from single markers:
303303
// camera parameters are read from somewhere
304304
readCameraParameters(cameraMatrix, distCoeffs);
305305

306-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
306+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
307307

308308
while (inputVideo.grab()) {
309309
cv::Mat image, imageCopy;
310310
inputVideo.retrieve(image);
311311
image.copyTo(imageCopy);
312312

313313
std::vector<int> ids;
314-
std::vector<std::vector<cv::Point2f> > corners;
314+
std::vector<std::vector<cv::Point2f>> corners;
315315
cv::aruco::detectMarkers(image, dictionary, corners, ids);
316316

317317
// if at least one marker detected
318318
if (ids.size() > 0) {
319319
cv::aruco::drawDetectedMarkers(imageCopy, corners, ids);
320320

321-
vector< Mat > rvecs, tvecs;
321+
std::vector<cv::Mat> rvecs, tvecs;
322322
cv::aruco::estimatePoseSingleMarkers(corners, 0.05, cameraMatrix, distCoeffs, rvecs, tvecs);
323323
// draw axis for each marker
324324
for(int i=0; i<ids.size(); i++)
@@ -374,7 +374,7 @@ This is the easiest way to select a dictionary. The aruco module includes a set
374374
of a variety of marker sizes and number of markers. For instance:
375375

376376
``` c++
377-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
377+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
378378
```
379379

380380
DICT_6X6_250 is an example of predefined dictionary of markers with 6x6 bits and a total of 250
@@ -390,7 +390,7 @@ The dictionary can be generated automatically to adjust to the desired number of
390390
the inter-marker distance is optimized:
391391

392392
``` c++
393-
cv::aruco::Dictionary dictionary = cv::aruco::generateCustomDictionary(36, 5);
393+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::generateCustomDictionary(36, 5);
394394
```
395395

396396
This will generate a customized dictionary composed by 36 markers of 5x5 bits. The process can take several
@@ -432,18 +432,19 @@ Fortunately, a marker can be easily transformed to this form using the static me
432432
For example:
433433

434434
``` c++
435-
Dictionary dictionary;
435+
cv::aruco::Dictionary dictionary;
436436
// markers of 6x6 bits
437437
dictionary.markerSize = 6;
438438
// maximum number of bit corrections
439439
dictionary.maxCorrectionBits = 3;
440440

441441
// lets create a dictionary of 100 markers
442442
for(int i=0; i<100; i++)
443+
{
443444
// assume generateMarkerBits() generate a new marker in binary format, so that
444445
// markerBits is a 6x6 matrix of CV_8UC1 type, only containing 0s and 1s
445446
cv::Mat markerBits = generateMarkerBits();
446-
cv::Mat markerCompressed = getByteListFromBits(markerBits);
447+
cv::Mat markerCompressed = cv::aruco::Dictionary::getByteListFromBits(markerBits);
447448
// add the marker as a new row
448449
dictionary.bytesList.push_back(markerCompressed);
449450
}

modules/aruco/tutorials/charuco_detection/charuco_detection.markdown

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ Once we have our ```CharucoBoard``` object, we can create an image to print it.
6060
```CharucoBoard::draw()``` method:
6161

6262
``` c++
63-
cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
63+
cv::Ptr<cv::aruco::CharucoBoard> board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
6464
cv::Mat boardImage;
65-
board.draw( cv::Size(600, 500), boardImage, 10, 1 );
65+
board->draw( cv::Size(600, 500), boardImage, 10, 1 );
6666
```
6767
6868
- The first parameter is the size of the output image in pixels. In this case 600x500 pixels. If this is not proportional
@@ -94,8 +94,8 @@ in the board.
9494

9595
So, a detected ChArUco board consists in:
9696

97-
- ```vector<Point2f> charucoCorners``` : list of image positions of the detected corners.
98-
- ```vector <int> charucoIds``` : ids for each of the detected corners in ```charucoCorners```.
97+
- ```std::vector<cv::Point2f> charucoCorners``` : list of image positions of the detected corners.
98+
- ```std::vector<int> charucoIds``` : ids for each of the detected corners in ```charucoCorners```.
9999

100100
The detection of the ChArUco corners is based on the previous detected markers. So that, first markers are detected, and then
101101
ChArUco corners are interpolated from markers.
@@ -107,11 +107,11 @@ The function that detect the ChArUco corners is ```cv::aruco::interpolateCorners
107107
cv::Mat cameraMatrix, distCoeffs;
108108
// camera parameters are read from somewhere
109109
readCameraParameters(cameraMatrix, distCoeffs);
110-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
111-
cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
110+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
111+
cv::Ptr<cv::aruco::CharucoBoard> board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
112112
...
113-
vector< int > markerIds;
114-
vector< vector<Point2f> > markerCorners;
113+
std::vector<int> markerIds;
114+
std::vector<std::vector<cv::Point2f>> markerCorners;
115115
cv::aruco::detectMarkers(inputImage, board.dictionary, markerCorners, markerIds);
116116

117117
// if at least one marker detected
@@ -136,13 +136,13 @@ are optional. A similar example without these parameters would be:
136136
137137
``` c++
138138
cv::Mat inputImage;
139-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
140-
cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
139+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
140+
cv::Ptr<cv::aruco::CharucoBoard> board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
141141
...
142-
vector< int > markerIds;
143-
vector< vector<Point2f> > markerCorners;
144-
DetectorParameters params;
145-
params.doCornerRefinement = false;
142+
std::vector<int> markerIds;
143+
std::vector<std::vector<cv::Point2f>> markerCorners;
144+
cv::Ptr<cv::aruco::DetectorParameters> params;
145+
params->doCornerRefinement = false;
146146
cv::aruco::detectMarkers(inputImage, board.dictionary, markerCorners, markerIds, params);
147147
148148
// if at least one marker detected
@@ -203,19 +203,19 @@ Finally, this is a full example of ChArUco detection (without using calibration
203203
cv::VideoCapture inputVideo;
204204
inputVideo.open(0);
205205
206-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
207-
cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
206+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
207+
cv::Ptr<cv::aruco::CharucoBoard> board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
208208
209-
DetectorParameters params;
210-
params.doCornerRefinement = false;
209+
cv::Ptr<cv::aruco::DetectorParameters> params;
210+
params->doCornerRefinement = false;
211211
212212
while (inputVideo.grab()) {
213213
cv::Mat image, imageCopy;
214214
inputVideo.retrieve(image);
215215
image.copyTo(imageCopy);
216216
217217
std::vector<int> ids;
218-
std::vector<std::vector<cv::Point2f> > corners;
218+
std::vector<std::vector<cv::Point2f>> corners;
219219
cv::aruco::detectMarkers(image, dictionary, corners, ids, params);
220220
221221
// if at least one marker detected
@@ -286,16 +286,16 @@ A full example of ChArUco detection with pose estimation:
286286
// camera parameters are read from somewhere
287287
readCameraParameters(cameraMatrix, distCoeffs);
288288
289-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
290-
cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
289+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
290+
cv::Ptr<cv::aruco::CharucoBoard> board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary);
291291
292292
while (inputVideo.grab()) {
293293
cv::Mat image, imageCopy;
294294
inputVideo.retrieve(image);
295295
image.copyTo(imageCopy);
296296
297297
std::vector<int> ids;
298-
std::vector<std::vector<cv::Point2f> > corners;
298+
std::vector<std::vector<cv::Point2f>> corners;
299299
cv::aruco::detectMarkers(image, dictionary, corners, ids);
300300
301301
// if at least one marker detected

modules/aruco/tutorials/charuco_diamond_detection/charuco_diamond_detection.markdown

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ For instance:
4646

4747
``` c++
4848
cv::Mat diamondImage;
49-
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
49+
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
5050
cv::aruco::drawCharucoDiamond(dictionary, cv::Vec4i(45,68,28,74), 200, 120, markerImage);
5151
```
5252
@@ -78,14 +78,14 @@ After detecting markers, diamond are detected using the ```detectCharucoDiamond(
7878
...
7979

8080

81-
std::vector< int > markerIds;
82-
std::vector< std::vector< cv::Point2f > > markerCorners;
81+
std::vector<int> markerIds;
82+
std::vector<std::vector< cv::Point2f>> markerCorners;
8383

8484
// detect ArUco markers
8585
cv::aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds);
8686

87-
std::vector< cv::Vec4i > diamondIds;
88-
std::vector< std::vector< cv::Point2f > > diamondCorners;
87+
std::vector<cv::Vec4i> diamondIds;
88+
std::vector<std::vector<cv::Point2f>> diamondCorners;
8989

9090
// detect diamon diamonds
9191
cv::aruco::detectCharucoDiamond(inputImage, markerCorners, markerIds, squareLength / markerLength, diamondCorners, diamondIds);
@@ -107,8 +107,8 @@ corners and ids:
107107
108108
``` c++
109109
...
110-
std::vector< cv::Vec4i > diamondIds;
111-
std::vector< std::vector< cv::Point2f > > diamondCorners;
110+
std::vector<cv::Vec4i> diamondIds;
111+
std::vector<std::vector<cv::Point2f>> diamondCorners;
112112
cv::aruco::detectCharucoDiamond(inputImage, markerCorners, markerIds, squareLength / markerLength, diamondCorners, diamondIds);
113113
114114
cv::aruco::drawDetectedDiamonds(inputImage, diamondCorners, diamondIds);
@@ -134,8 +134,8 @@ i.e. using the ```estimatePoseSingleMarkers()``` function. For instance:
134134
``` c++
135135
...
136136

137-
std::vector< cv::Vec4i > diamondIds;
138-
std::vector< std::vector< cv::Point2f > > diamondCorners;
137+
std::vector<cv::Vec4i> diamondIds;
138+
std::vector<std::vector<cv::Point2f>> diamondCorners;
139139

140140
// detect diamon diamonds
141141
cv::aruco::detectCharucoDiamond(inputImage, markerCorners, markerIds, squareLength / markerLength, diamondCorners, diamondIds);

0 commit comments

Comments
 (0)