@@ -45,6 +45,7 @@ the use of this software, even if advised of the possibility of such damage.
4545#include < vector>
4646#include < iostream>
4747#include < ctime>
48+ #include " aruco_samples_utility.hpp"
4849
4950using namespace std ;
5051using namespace cv ;
@@ -65,6 +66,7 @@ const char* keys =
6566 " DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
6667 " DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
6768 " DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
69+ " {cd | | Input file with custom dictionary }"
6870 " {@outfile |<none> | Output file with calibrated camera parameters }"
6971 " {v | | Input from video file, if ommited, input comes from camera }"
7072 " {ci | 0 | Camera id if input doesnt come from video (-v) }"
@@ -75,80 +77,7 @@ const char* keys =
7577 " {pc | false | Fix the principal point at the center }" ;
7678}
7779
78- /* *
79- */
80- static bool readDetectorParameters (string filename, Ptr<aruco::DetectorParameters> ¶ms) {
81- FileStorage fs (filename, FileStorage::READ);
82- if (!fs.isOpened ())
83- return false ;
84- fs[" adaptiveThreshWinSizeMin" ] >> params->adaptiveThreshWinSizeMin ;
85- fs[" adaptiveThreshWinSizeMax" ] >> params->adaptiveThreshWinSizeMax ;
86- fs[" adaptiveThreshWinSizeStep" ] >> params->adaptiveThreshWinSizeStep ;
87- fs[" adaptiveThreshConstant" ] >> params->adaptiveThreshConstant ;
88- fs[" minMarkerPerimeterRate" ] >> params->minMarkerPerimeterRate ;
89- fs[" maxMarkerPerimeterRate" ] >> params->maxMarkerPerimeterRate ;
90- fs[" polygonalApproxAccuracyRate" ] >> params->polygonalApproxAccuracyRate ;
91- fs[" minCornerDistanceRate" ] >> params->minCornerDistanceRate ;
92- fs[" minDistanceToBorder" ] >> params->minDistanceToBorder ;
93- fs[" minMarkerDistanceRate" ] >> params->minMarkerDistanceRate ;
94- fs[" cornerRefinementMethod" ] >> params->cornerRefinementMethod ;
95- fs[" cornerRefinementWinSize" ] >> params->cornerRefinementWinSize ;
96- fs[" cornerRefinementMaxIterations" ] >> params->cornerRefinementMaxIterations ;
97- fs[" cornerRefinementMinAccuracy" ] >> params->cornerRefinementMinAccuracy ;
98- fs[" markerBorderBits" ] >> params->markerBorderBits ;
99- fs[" perspectiveRemovePixelPerCell" ] >> params->perspectiveRemovePixelPerCell ;
100- fs[" perspectiveRemoveIgnoredMarginPerCell" ] >> params->perspectiveRemoveIgnoredMarginPerCell ;
101- fs[" maxErroneousBitsInBorderRate" ] >> params->maxErroneousBitsInBorderRate ;
102- fs[" minOtsuStdDev" ] >> params->minOtsuStdDev ;
103- fs[" errorCorrectionRate" ] >> params->errorCorrectionRate ;
104- return true ;
105- }
106-
107-
108-
109- /* *
110- */
111- static bool saveCameraParams (const string &filename, Size imageSize, float aspectRatio, int flags,
112- const Mat &cameraMatrix, const Mat &distCoeffs, double totalAvgErr) {
113- FileStorage fs (filename, FileStorage::WRITE);
114- if (!fs.isOpened ())
115- return false ;
116-
117- time_t tt;
118- time (&tt);
119- struct tm *t2 = localtime (&tt);
120- char buf[1024 ];
121- strftime (buf, sizeof (buf) - 1 , " %c" , t2);
122-
123- fs << " calibration_time" << buf;
124-
125- fs << " image_width" << imageSize.width ;
126- fs << " image_height" << imageSize.height ;
127-
128- if (flags & CALIB_FIX_ASPECT_RATIO) fs << " aspectRatio" << aspectRatio;
129-
130- if (flags != 0 ) {
131- sprintf (buf, " flags: %s%s%s%s" ,
132- flags & CALIB_USE_INTRINSIC_GUESS ? " +use_intrinsic_guess" : " " ,
133- flags & CALIB_FIX_ASPECT_RATIO ? " +fix_aspectRatio" : " " ,
134- flags & CALIB_FIX_PRINCIPAL_POINT ? " +fix_principal_point" : " " ,
135- flags & CALIB_ZERO_TANGENT_DIST ? " +zero_tangent_dist" : " " );
136- }
137-
138- fs << " flags" << flags;
139-
140- fs << " camera_matrix" << cameraMatrix;
141- fs << " distortion_coefficients" << distCoeffs;
14280
143- fs << " avg_reprojection_error" << totalAvgErr;
144-
145- return true ;
146- }
147-
148-
149-
150- /* *
151- */
15281int main (int argc, char *argv[]) {
15382 CommandLineParser parser (argc, argv, keys);
15483 parser.about (about);
@@ -162,7 +91,6 @@ int main(int argc, char *argv[]) {
16291 int markersY = parser.get <int >(" h" );
16392 float markerLength = parser.get <float >(" l" );
16493 float markerSeparation = parser.get <float >(" s" );
165- int dictionaryId = parser.get <int >(" d" );
16694 string outputFile = parser.get <String>(0 );
16795
16896 int calibrationFlags = 0 ;
@@ -174,9 +102,10 @@ int main(int argc, char *argv[]) {
174102 if (parser.get <bool >(" zt" )) calibrationFlags |= CALIB_ZERO_TANGENT_DIST;
175103 if (parser.get <bool >(" pc" )) calibrationFlags |= CALIB_FIX_PRINCIPAL_POINT;
176104
177- Ptr<aruco::DetectorParameters> detectorParams = aruco::DetectorParameters::create () ;
105+ Ptr<aruco::DetectorParameters> detectorParams;
178106 if (parser.has (" dp" )) {
179- bool readOk = readDetectorParameters (parser.get <string>(" dp" ), detectorParams);
107+ FileStorage fs (parser.get <string>(" dp" ), FileStorage::READ);
108+ bool readOk = aruco::DetectorParameters::readDetectorParameters (fs.root (), detectorParams);
180109 if (!readOk) {
181110 cerr << " Invalid detector parameters file" << endl;
182111 return 0 ;
@@ -206,8 +135,23 @@ int main(int argc, char *argv[]) {
206135 waitTime = 10 ;
207136 }
208137
209- Ptr<aruco::Dictionary> dictionary =
210- aruco::getPredefinedDictionary (aruco::PREDEFINED_DICTIONARY_NAME (dictionaryId));
138+ Ptr<aruco::Dictionary> dictionary;
139+ if (parser.has (" d" )) {
140+ int dictionaryId = parser.get <int >(" d" );
141+ dictionary = aruco::getPredefinedDictionary (aruco::PREDEFINED_DICTIONARY_NAME (dictionaryId));
142+ }
143+ else if (parser.has (" cd" )) {
144+ FileStorage fs (parser.get <std::string>(" cd" ), FileStorage::READ);
145+ bool readOk = aruco::Dictionary::readDictionary (fs.root (), dictionary);
146+ if (!readOk) {
147+ cerr << " Invalid dictionary file" << endl;
148+ return 0 ;
149+ }
150+ }
151+ else {
152+ cerr << " Dictionary not specified" << endl;
153+ return 0 ;
154+ }
211155
212156 // create board object
213157 Ptr<aruco::GridBoard> gridboard =
0 commit comments