@@ -43,7 +43,7 @@ the use of this software, even if advised of the possibility of such damage.
4343#include < opencv2/imgproc.hpp>
4444#include < vector>
4545#include < iostream>
46- #include < ctime >
46+ #include " aruco_samples_utility.hpp "
4747
4848using namespace std ;
4949using namespace cv ;
@@ -63,6 +63,7 @@ const char* keys =
6363 " DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
6464 " DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
6565 " DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
66+ " {cd | | Input file with custom dictionary }"
6667 " {@outfile |<none> | Output file with calibrated camera parameters }"
6768 " {v | | Input from video file, if ommited, input comes from camera }"
6869 " {ci | 0 | Camera id if input doesnt come from video (-v) }"
@@ -74,80 +75,7 @@ const char* keys =
7475 " {sc | false | Show detected chessboard corners after calibration }" ;
7576}
7677
77- /* *
78- */
79- static bool readDetectorParameters (string filename, Ptr<aruco::DetectorParameters> ¶ms) {
80- FileStorage fs (filename, FileStorage::READ);
81- if (!fs.isOpened ())
82- return false ;
83- fs[" adaptiveThreshWinSizeMin" ] >> params->adaptiveThreshWinSizeMin ;
84- fs[" adaptiveThreshWinSizeMax" ] >> params->adaptiveThreshWinSizeMax ;
85- fs[" adaptiveThreshWinSizeStep" ] >> params->adaptiveThreshWinSizeStep ;
86- fs[" adaptiveThreshConstant" ] >> params->adaptiveThreshConstant ;
87- fs[" minMarkerPerimeterRate" ] >> params->minMarkerPerimeterRate ;
88- fs[" maxMarkerPerimeterRate" ] >> params->maxMarkerPerimeterRate ;
89- fs[" polygonalApproxAccuracyRate" ] >> params->polygonalApproxAccuracyRate ;
90- fs[" minCornerDistanceRate" ] >> params->minCornerDistanceRate ;
91- fs[" minDistanceToBorder" ] >> params->minDistanceToBorder ;
92- fs[" minMarkerDistanceRate" ] >> params->minMarkerDistanceRate ;
93- fs[" cornerRefinementMethod" ] >> params->cornerRefinementMethod ;
94- fs[" cornerRefinementWinSize" ] >> params->cornerRefinementWinSize ;
95- fs[" cornerRefinementMaxIterations" ] >> params->cornerRefinementMaxIterations ;
96- fs[" cornerRefinementMinAccuracy" ] >> params->cornerRefinementMinAccuracy ;
97- fs[" markerBorderBits" ] >> params->markerBorderBits ;
98- fs[" perspectiveRemovePixelPerCell" ] >> params->perspectiveRemovePixelPerCell ;
99- fs[" perspectiveRemoveIgnoredMarginPerCell" ] >> params->perspectiveRemoveIgnoredMarginPerCell ;
100- fs[" maxErroneousBitsInBorderRate" ] >> params->maxErroneousBitsInBorderRate ;
101- fs[" minOtsuStdDev" ] >> params->minOtsuStdDev ;
102- fs[" errorCorrectionRate" ] >> params->errorCorrectionRate ;
103- return true ;
104- }
105-
106-
107-
108- /* *
109- */
110- static bool saveCameraParams (const string &filename, Size imageSize, float aspectRatio, int flags,
111- const Mat &cameraMatrix, const Mat &distCoeffs, double totalAvgErr) {
112- FileStorage fs (filename, FileStorage::WRITE);
113- if (!fs.isOpened ())
114- return false ;
115-
116- time_t tt;
117- time (&tt);
118- struct tm *t2 = localtime (&tt);
119- char buf[1024 ];
120- strftime (buf, sizeof (buf) - 1 , " %c" , t2);
121-
122- fs << " calibration_time" << buf;
123-
124- fs << " image_width" << imageSize.width ;
125- fs << " image_height" << imageSize.height ;
126-
127- if (flags & CALIB_FIX_ASPECT_RATIO) fs << " aspectRatio" << aspectRatio;
128-
129- if (flags != 0 ) {
130- sprintf (buf, " flags: %s%s%s%s" ,
131- flags & CALIB_USE_INTRINSIC_GUESS ? " +use_intrinsic_guess" : " " ,
132- flags & CALIB_FIX_ASPECT_RATIO ? " +fix_aspectRatio" : " " ,
133- flags & CALIB_FIX_PRINCIPAL_POINT ? " +fix_principal_point" : " " ,
134- flags & CALIB_ZERO_TANGENT_DIST ? " +zero_tangent_dist" : " " );
135- }
136-
137- fs << " flags" << flags;
138-
139- fs << " camera_matrix" << cameraMatrix;
140- fs << " distortion_coefficients" << distCoeffs;
14178
142- fs << " avg_reprojection_error" << totalAvgErr;
143-
144- return true ;
145- }
146-
147-
148-
149- /* *
150- */
15179int main (int argc, char *argv[]) {
15280 CommandLineParser parser (argc, argv, keys);
15381 parser.about (about);
@@ -161,7 +89,6 @@ int main(int argc, char *argv[]) {
16189 int squaresY = parser.get <int >(" h" );
16290 float squareLength = parser.get <float >(" sl" );
16391 float markerLength = parser.get <float >(" ml" );
164- int dictionaryId = parser.get <int >(" d" );
16592 string outputFile = parser.get <string>(0 );
16693
16794 bool showChessboardCorners = parser.get <bool >(" sc" );
@@ -207,8 +134,22 @@ int main(int argc, char *argv[]) {
207134 waitTime = 10 ;
208135 }
209136
210- Ptr<aruco::Dictionary> dictionary =
211- aruco::getPredefinedDictionary (aruco::PREDEFINED_DICTIONARY_NAME (dictionaryId));
137+ Ptr<aruco::Dictionary> dictionary;
138+ if (parser.has (" d" )) {
139+ int dictionaryId = parser.get <int >(" d" );
140+ dictionary = aruco::getPredefinedDictionary (aruco::PREDEFINED_DICTIONARY_NAME (dictionaryId));
141+ }
142+ else if (parser.has (" cd" )) {
143+ bool readOk = readDictionary (parser.get <string>(" cd" ), dictionary);
144+ if (!readOk) {
145+ cerr << " Invalid dictionary file" << endl;
146+ return 0 ;
147+ }
148+ }
149+ else {
150+ cerr << " Dictionary not specified" << endl;
151+ return 0 ;
152+ }
212153
213154 // create charuco board object
214155 Ptr<aruco::CharucoBoard> charucoboard =
0 commit comments