Skip to content

Commit 7b106d6

Browse files
author
AleksandrPanov
committed
fixing
1 parent 6277302 commit 7b106d6

10 files changed

+65
-531
lines changed

modules/aruco/samples/aruco_samples_utility.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,51 @@ inline static bool saveCameraParams(const std::string &filename, cv::Size imageS
4545
return true;
4646
}
4747

48+
49+
inline static cv::aruco::DetectorParameters readDetectorParamsFromCommandLine(cv::CommandLineParser &parser) {
50+
cv::aruco::DetectorParameters detectorParams;
51+
if (parser.has("dp")) {
52+
cv::FileStorage fs(parser.get<std::string>("dp"), cv::FileStorage::READ);
53+
bool readOk = detectorParams.readDetectorParameters(fs.root());
54+
if(!readOk) {
55+
std::cerr << "Invalid detector parameters file" << std::endl;
56+
throw -1;
57+
}
58+
}
59+
return detectorParams;
60+
}
61+
62+
inline static void readCameraParamsFromCommandLine(cv::CommandLineParser &parser, cv::Mat& camMatrix, cv::Mat& distCoeffs) {
63+
//! [camDistCoeffs]
64+
if(parser.has("c")) {
65+
bool readOk = readCameraParameters(parser.get<std::string>("c"), camMatrix, distCoeffs);
66+
if(!readOk) {
67+
std::cerr << "Invalid camera file" << std::endl;
68+
throw -1;
69+
}
70+
}
71+
//! [camDistCoeffs]
72+
}
73+
74+
inline static cv::aruco::Dictionary readDictionatyFromCommandLine(cv::CommandLineParser &parser) {
75+
cv::aruco::Dictionary dictionary;
76+
if (parser.has("cd")) {
77+
cv::FileStorage fs(parser.get<std::string>("cd"), cv::FileStorage::READ);
78+
bool readOk = dictionary.readDictionary(fs.root());
79+
if(!readOk) {
80+
std::cerr << "Invalid dictionary file" << std::endl;
81+
throw -1;
82+
}
83+
}
84+
else {
85+
int dictionaryId = parser.has("d") ? parser.get<int>("d"): cv::aruco::DICT_4X4_50;
86+
if (!parser.has("d")) {
87+
std::cout << "The default DICT_4X4_50 dictionary has been selected, you could "
88+
"select the specific dictionary using flags -d or -cd." << std::endl;
89+
}
90+
dictionary = cv::aruco::getPredefinedDictionary(dictionaryId);
91+
}
92+
return dictionary;
93+
}
94+
4895
}

modules/aruco/samples/calibrate_camera.cpp

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,8 @@ int main(int argc, char *argv[]) {
6262
if(parser.get<bool>("zt")) calibrationFlags |= CALIB_ZERO_TANGENT_DIST;
6363
if(parser.get<bool>("pc")) calibrationFlags |= CALIB_FIX_PRINCIPAL_POINT;
6464

65-
aruco::DetectorParameters detectorParams;
66-
if(parser.has("dp")) {
67-
FileStorage fs(parser.get<string>("dp"), FileStorage::READ);
68-
bool readOk = detectorParams.readDetectorParameters(fs.root());
69-
if(!readOk) {
70-
cerr << "Invalid detector parameters file" << endl;
71-
return 0;
72-
}
73-
}
65+
aruco::Dictionary dictionary = readDictionatyFromCommandLine(parser);
66+
aruco::DetectorParameters detectorParams = readDetectorParamsFromCommandLine(parser);
7467

7568
bool refindStrategy = parser.get<bool>("rs");
7669
int camId = parser.get<int>("ci");
@@ -95,26 +88,6 @@ int main(int argc, char *argv[]) {
9588
waitTime = 10;
9689
}
9790

98-
aruco::Dictionary dictionary = aruco::getPredefinedDictionary(aruco::DICT_4X4_50);
99-
if (parser.has("d")) {
100-
int dictionaryId = parser.get<int>("d");
101-
dictionary = aruco::getPredefinedDictionary(
102-
aruco::PredefinedDictionaryType(dictionaryId)
103-
);
104-
}
105-
else if (parser.has("cd")) {
106-
FileStorage fs(parser.get<std::string>("cd"), FileStorage::READ);
107-
bool readOk = dictionary.aruco::Dictionary::readDictionary(fs.root());
108-
if(!readOk) {
109-
cerr << "Invalid dictionary file" << endl;
110-
return 0;
111-
}
112-
}
113-
else {
114-
cerr << "Dictionary not specified" << endl;
115-
return 0;
116-
}
117-
11891
//! [CalibrationWithArucoBoard1]
11992
// Create board object and ArucoDetector
12093
aruco::GridBoard gridboard(Size(markersX, markersY), markerLength, markerSeparation, dictionary);

modules/aruco/samples/calibrate_camera_charuco.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,8 @@ int main(int argc, char *argv[]) {
6363
if(parser.get<bool>("zt")) calibrationFlags |= CALIB_ZERO_TANGENT_DIST;
6464
if(parser.get<bool>("pc")) calibrationFlags |= CALIB_FIX_PRINCIPAL_POINT;
6565

66-
aruco::DetectorParameters detectorParams = aruco::DetectorParameters();
67-
if(parser.has("dp")) {
68-
FileStorage fs(parser.get<string>("dp"), FileStorage::READ);
69-
bool readOk = detectorParams.readDetectorParameters(fs.root());
70-
if(!readOk) {
71-
cerr << "Invalid detector parameters file" << endl;
72-
return 0;
73-
}
74-
}
66+
aruco::DetectorParameters detectorParams = readDetectorParamsFromCommandLine(parser);
67+
aruco::Dictionary dictionary = readDictionatyFromCommandLine(parser);
7568

7669
bool refindStrategy = parser.get<bool>("rs");
7770
int camId = parser.get<int>("ci");
@@ -96,24 +89,6 @@ int main(int argc, char *argv[]) {
9689
waitTime = 10;
9790
}
9891

99-
aruco::Dictionary dictionary = aruco::getPredefinedDictionary(0);
100-
if (parser.has("d")) {
101-
int dictionaryId = parser.get<int>("d");
102-
dictionary = aruco::getPredefinedDictionary(aruco::PredefinedDictionaryType(dictionaryId));
103-
}
104-
else if (parser.has("cd")) {
105-
FileStorage fs(parser.get<std::string>("cd"), FileStorage::READ);
106-
bool readOk = dictionary.aruco::Dictionary::readDictionary(fs.root());
107-
if(!readOk) {
108-
cerr << "Invalid dictionary file" << endl;
109-
return 0;
110-
}
111-
}
112-
else {
113-
cerr << "Dictionary not specified" << endl;
114-
return 0;
115-
}
116-
11792
aruco::CharucoParameters charucoParams;
11893
if(refindStrategy) {
11994
charucoParams.tryRefineMarkers = true;

modules/aruco/samples/create_board.cpp

Lines changed: 0 additions & 132 deletions
This file was deleted.

modules/aruco/samples/create_board_charuco.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,35 +52,17 @@ int main(int argc, char *argv[]) {
5252
return 0;
5353
}
5454

55-
aruco::Dictionary dictionary = aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_50);
56-
if (parser.has("d")) {
57-
int dictionaryId = parser.get<int>("d");
58-
dictionary = aruco::getPredefinedDictionary(aruco::PredefinedDictionaryType(dictionaryId));
59-
}
60-
else if (parser.has("cd")) {
61-
FileStorage fs(parser.get<std::string>("cd"), FileStorage::READ);
62-
bool readOk = dictionary.aruco::Dictionary::readDictionary(fs.root());
63-
if(!readOk) {
64-
std::cerr << "Invalid dictionary file" << std::endl;
65-
return 0;
66-
}
67-
}
68-
else {
69-
std::cout << "The default DICT_4X4_50 dictionary has been selected, you could "
70-
"select the specific dictionary using flags -d or -cd." << std::endl;
71-
}
72-
73-
Size imageSize;
74-
imageSize.width = squaresX * squareLength + 2 * margins;
75-
imageSize.height = squaresY * squareLength + 2 * margins;
76-
7755
//! [create_charucoBoard]
56+
aruco::Dictionary dictionary = readDictionatyFromCommandLine(parser);
7857
cv::aruco::CharucoBoard board(Size(squaresX, squaresY), (float)squareLength, (float)markerLength, dictionary);
7958
//! [create_charucoBoard]
8059

8160
// show created board
8261
//! [generate_charucoBoard]
8362
Mat boardImage;
63+
Size imageSize;
64+
imageSize.width = squaresX * squareLength + 2 * margins;
65+
imageSize.height = squaresY * squareLength + 2 * margins;
8466
board.generateImage(imageSize, boardImage, margins, borderBits);
8567
//! [generate_charucoBoard]
8668

modules/aruco/samples/create_diamond.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <opencv2/objdetect/charuco_detector.hpp>
33
#include <vector>
44
#include <iostream>
5+
#include "aruco_samples_utility.hpp"
56

67
using namespace std;
78
using namespace cv;
@@ -32,28 +33,18 @@ int main(int argc, char *argv[]) {
3233

3334
int squareLength = parser.get<int>("sl");
3435
int markerLength = parser.get<int>("ml");
35-
int dictionaryId = parser.get<int>("d");
3636
string idsString = parser.get<string>("ids");
3737
int margins = parser.get<int>("m");
3838
int borderBits = parser.get<int>("bb");
3939
bool showImage = parser.get<bool>("si");
4040
string out = parser.get<string>(0);
41+
aruco::Dictionary dictionary = readDictionatyFromCommandLine(parser);
4142

4243
if(!parser.check()) {
4344
parser.printErrors();
4445
return 0;
4546
}
4647

47-
aruco::Dictionary dictionary = aruco::getPredefinedDictionary(aruco::PredefinedDictionaryType(dictionaryId));
48-
if (parser.has("cd")) {
49-
FileStorage fs(parser.get<std::string>("cd"), FileStorage::READ);
50-
bool readOk = dictionary.aruco::Dictionary::readDictionary(fs.root());
51-
if(!readOk) {
52-
cerr << "Invalid dictionary file" << endl;
53-
return 0;
54-
}
55-
}
56-
5748
istringstream ss(idsString);
5849
vector<string> splittedIds;
5950
string token;

0 commit comments

Comments
 (0)