Commit 745d8194 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #445 from paroj:use_cliparser

parents 0b5f2574 6b90a405
...@@ -49,59 +49,31 @@ using namespace std; ...@@ -49,59 +49,31 @@ using namespace std;
using namespace cv; using namespace cv;
/** namespace {
*/ const char* about =
static void help() { "Calibration using a ArUco Planar Grid board\n"
cout << "Calibration using a ArUco Planar Grid board" << endl; " To capture a frame for calibration, press 'c',\n"
cout << "How to Use:" << endl; " If input comes from video, press any key for next frame\n"
cout << "To capture a frame for calibration, press 'c'," << endl; " To finish capturing, press 'ESC' key and calibration starts.\n";
cout << "If input comes from video, press any key for next frame" << endl; const char* keys =
cout << "To finish capturing, press 'ESC' key and calibration starts." << endl; "{w | | Number of squares in X direction }"
cout << "Parameters: " << endl; "{h | | Number of squares in Y direction }"
cout << "-w <nmarkers> # Number of markers in X direction" << endl; "{l | | Marker side lenght (in meters) }"
cout << "-h <nmarkers> # Number of markers in Y direction" << endl; "{s | | Separation between two consecutive markers in the grid (in meters) }"
cout << "-l <markerLength> # Marker side lenght (in meters)" << endl; "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "-s <markerSeparation> # Separation between two consecutive" "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
<< "markers in the grid (in meters)" << endl; "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "{@outfile |<none> | Output file with calibrated camera parameters }"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{v | | Input from video file, if ommited, input comes from camera }"
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl; "{ci | 0 | Camera id if input doesnt come from video (-v) }"
cout << "-o <outputFile> # Output file with calibrated camera parameters" << endl; "{dp | | File of marker detector parameters }"
cout << "[-v <videoFile>] # Input from video file, if ommited, input comes from camera" << endl; "{rs | false | Apply refind strategy }"
cout << "[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0" << endl; "{zt | false | Assume zero tangential distortion }"
cout << "[-dp <detectorParams>] # File of marker detector parameters" << endl; "{a | | Fix aspect ratio (fx/fy) to this value }"
cout << "[-rs] # Apply refind strategy" << endl; "{pc | false | Fix the principal point at the center }";
cout << "[-zt] # Assume zero tangential distortion" << endl;
cout << "[-a <aspectRatio>] # Fix aspect ratio (fx/fy)" << endl;
cout << "[-p] # Fix the principal point at the center" << endl;
} }
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
}
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
}
/** /**
*/ */
static bool readDetectorParameters(string filename, aruco::DetectorParameters &params) { static bool readDetectorParameters(string filename, aruco::DetectorParameters &params) {
...@@ -177,55 +149,65 @@ static bool saveCameraParams(const string &filename, Size imageSize, float aspec ...@@ -177,55 +149,65 @@ static bool saveCameraParams(const string &filename, Size imageSize, float aspec
/** /**
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(!isParam("-w", argc, argv) || !isParam("-h", argc, argv) || !isParam("-l", argc, argv) || if(argc < 6) {
!isParam("-s", argc, argv) || !isParam("-d", argc, argv) || !isParam("-o", argc, argv)) { parser.printMessage();
help();
return 0; return 0;
} }
int markersX = atoi(getParam("-w", argc, argv).c_str()); int markersX = parser.get<int>("w");
int markersY = atoi(getParam("-h", argc, argv).c_str()); int markersY = parser.get<int>("w");
float markerLength = (float)atof(getParam("-l", argc, argv).c_str()); float markerLength = parser.get<float>("l");
float markerSeparation = (float)atof(getParam("-s", argc, argv).c_str()); float markerSeparation = parser.get<float>("s");
int dictionaryId = atoi(getParam("-d", argc, argv).c_str()); int dictionaryId = parser.get<int>("d");
aruco::Dictionary dictionary = string outputFile = parser.get<String>(0);
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
string outputFile = getParam("-o", argc, argv);
int calibrationFlags = 0; int calibrationFlags = 0;
float aspectRatio = 1; float aspectRatio = 1;
if(isParam("-a", argc, argv)) { if(parser.has("a")) {
calibrationFlags |= CALIB_FIX_ASPECT_RATIO; calibrationFlags |= CALIB_FIX_ASPECT_RATIO;
aspectRatio = (float)atof(getParam("-a", argc, argv).c_str()); aspectRatio = parser.get<float>("a");
} }
if(isParam("-zt", argc, argv)) calibrationFlags |= CALIB_ZERO_TANGENT_DIST; if(parser.get<bool>("zt")) calibrationFlags |= CALIB_ZERO_TANGENT_DIST;
if(isParam("-p", argc, argv)) calibrationFlags |= CALIB_FIX_PRINCIPAL_POINT; if(parser.get<bool>("pc")) calibrationFlags |= CALIB_FIX_PRINCIPAL_POINT;
aruco::DetectorParameters detectorParams; aruco::DetectorParameters detectorParams;
if(isParam("-dp", argc, argv)) { if(parser.has("dp")) {
bool readOk = readDetectorParameters(getParam("-dp", argc, argv), detectorParams); bool readOk = readDetectorParameters(parser.get<string>("dp"), detectorParams);
if(!readOk) { if(!readOk) {
cerr << "Invalid detector parameters file" << endl; cerr << "Invalid detector parameters file" << endl;
return 0; return 0;
} }
} }
bool refindStrategy = false; bool refindStrategy = parser.get<bool>("rs");
if(isParam("-rs", argc, argv)) refindStrategy = true; int camId = parser.get<int>("ci");
String video;
if(parser.has("v")) {
video = parser.get<String>("v");
}
if(!parser.check()) {
parser.printErrors();
return 0;
}
VideoCapture inputVideo; VideoCapture inputVideo;
int waitTime; int waitTime;
if(isParam("-v", argc, argv)) { if(!video.empty()) {
inputVideo.open(getParam("-v", argc, argv)); inputVideo.open(video);
waitTime = 0; waitTime = 0;
} else { } else {
int camId = 0;
if(isParam("-ci", argc, argv)) camId = atoi(getParam("-ci", argc, argv).c_str());
inputVideo.open(camId); inputVideo.open(camId);
waitTime = 10; waitTime = 10;
} }
aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
// create board object // create board object
aruco::GridBoard board = aruco::GridBoard board =
aruco::GridBoard::create(markersX, markersY, markerLength, markerSeparation, dictionary); aruco::GridBoard::create(markersX, markersY, markerLength, markerSeparation, dictionary);
......
...@@ -48,60 +48,32 @@ the use of this software, even if advised of the possibility of such damage. ...@@ -48,60 +48,32 @@ the use of this software, even if advised of the possibility of such damage.
using namespace std; using namespace std;
using namespace cv; using namespace cv;
namespace {
/** const char* about =
*/ "Calibration using a ChArUco board\n"
static void help() { " To capture a frame for calibration, press 'c',\n"
cout << "Calibration using a ChArUco board" << endl; " If input comes from video, press any key for next frame\n"
cout << "How to Use:" << endl; " To finish capturing, press 'ESC' key and calibration starts.\n";
cout << "To capture a frame for calibration, press 'c'," << endl; const char* keys =
cout << "If input comes from video, press any key for next frame" << endl; "{w | | Number of squares in X direction }"
cout << "To finish capturing, press 'ESC' key and calibration starts." << endl; "{h | | Number of squares in Y direction }"
cout << "Parameters: " << endl; "{sl | | Square side lenght (in pixels) }"
cout << "-w <nmarkers> # Number of markers in X direction" << endl; "{ml | | Marker side lenght (in pixels) }"
cout << "-h <nsquares> # Number of squares in Y direction" << endl; "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "-sl <squareLength> # Square side lenght (in meters)" << endl; "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
cout << "-ml <markerLength> # Marker side lenght (in meters)" << endl; "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "{@outfile |<none> | Output file with calibrated camera parameters }"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{v | | Input from video file, if ommited, input comes from camera }"
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl; "{ci | 0 | Camera id if input doesnt come from video (-v) }"
cout << "-o <outputFile> # Output file with calibrated camera parameters" << endl; "{dp | | File of marker detector parameters }"
cout << "[-v <videoFile>] # Input from video file, if ommited, input comes from camera" << endl; "{rs | false | Apply refind strategy }"
cout << "[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0" << endl; "{zt | false | Assume zero tangential distortion }"
cout << "[-dp <detectorParams>] # File of marker detector parameters" << endl; "{a | | Fix aspect ratio (fx/fy) to this value }"
cout << "[-rs] # Apply refind strategy" << endl; "{pc | false | Fix the principal point at the center }"
cout << "[-zt] # Assume zero tangential distortion" << endl; "{sc | false | Show detected chessboard corners after calibration }";
cout << "[-a <aspectRatio>] # Fix aspect ratio (fx/fy)" << endl;
cout << "[-p] # Fix the principal point at the center" << endl;
cout << "[-sc] # Show detected chessboard corners after calibration" << endl;
}
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
}
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
} }
/** /**
*/ */
static bool readDetectorParameters(string filename, aruco::DetectorParameters &params) { static bool readDetectorParameters(string filename, aruco::DetectorParameters &params) {
...@@ -177,57 +149,67 @@ static bool saveCameraParams(const string &filename, Size imageSize, float aspec ...@@ -177,57 +149,67 @@ static bool saveCameraParams(const string &filename, Size imageSize, float aspec
/** /**
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(!isParam("-w", argc, argv) || !isParam("-h", argc, argv) || !isParam("-sl", argc, argv) || if(argc < 7) {
!isParam("-ml", argc, argv) || !isParam("-d", argc, argv) || !isParam("-o", argc, argv)) { parser.printMessage();
help();
return 0; return 0;
} }
int squaresX = atoi(getParam("-w", argc, argv).c_str()); int squaresX = parser.get<int>("w");
int squaresY = atoi(getParam("-h", argc, argv).c_str()); int squaresY = parser.get<int>("h");
float squareLength = (float)atof(getParam("-sl", argc, argv).c_str()); float squareLength = parser.get<float>("sl");
float markerLength = (float)atof(getParam("-ml", argc, argv).c_str()); float markerLength = parser.get<float>("ml");
int dictionaryId = atoi(getParam("-d", argc, argv).c_str()); int dictionaryId = parser.get<int>("d");
aruco::Dictionary dictionary = string outputFile = parser.get<string>(0);
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
string outputFile = getParam("-o", argc, argv);
bool showChessboardCorners = isParam("-sc", argc, argv); bool showChessboardCorners = parser.get<bool>("sc");
int calibrationFlags = 0; int calibrationFlags = 0;
float aspectRatio = 1; float aspectRatio = 1;
if(isParam("-a", argc, argv)) { if(parser.has("a")) {
calibrationFlags |= CALIB_FIX_ASPECT_RATIO; calibrationFlags |= CALIB_FIX_ASPECT_RATIO;
aspectRatio = (float)atof(getParam("-a", argc, argv).c_str()); aspectRatio = parser.get<float>("a");
} }
if(isParam("-zt", argc, argv)) calibrationFlags |= CALIB_ZERO_TANGENT_DIST; if(parser.get<bool>("zt")) calibrationFlags |= CALIB_ZERO_TANGENT_DIST;
if(isParam("-p", argc, argv)) calibrationFlags |= CALIB_FIX_PRINCIPAL_POINT; if(parser.get<bool>("pc")) calibrationFlags |= CALIB_FIX_PRINCIPAL_POINT;
aruco::DetectorParameters detectorParams; aruco::DetectorParameters detectorParams;
if(isParam("-dp", argc, argv)) { if(parser.has("dp")) {
bool readOk = readDetectorParameters(getParam("-dp", argc, argv), detectorParams); bool readOk = readDetectorParameters(parser.get<string>("dp"), detectorParams);
if(!readOk) { if(!readOk) {
cerr << "Invalid detector parameters file" << endl; cerr << "Invalid detector parameters file" << endl;
return 0; return 0;
} }
} }
bool refindStrategy = false; bool refindStrategy = parser.get<bool>("rs");
if(isParam("-rs", argc, argv)) refindStrategy = true; int camId = parser.get<int>("ci");
String video;
if(parser.has("v")) {
video = parser.get<String>("v");
}
if(!parser.check()) {
parser.printErrors();
return 0;
}
VideoCapture inputVideo; VideoCapture inputVideo;
int waitTime; int waitTime;
if(isParam("-v", argc, argv)) { if(!video.empty()) {
inputVideo.open(getParam("-v", argc, argv)); inputVideo.open(video);
waitTime = 0; waitTime = 0;
} else { } else {
int camId = 0;
if(isParam("-ci", argc, argv)) camId = atoi(getParam("-ci", argc, argv).c_str());
inputVideo.open(camId); inputVideo.open(camId);
waitTime = 10; waitTime = 10;
} }
aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
// create charuco board object // create charuco board object
aruco::CharucoBoard board = aruco::CharucoBoard board =
aruco::CharucoBoard::create(squaresX, squaresY, squareLength, markerLength, dictionary); aruco::CharucoBoard::create(squaresX, squaresY, squareLength, markerLength, dictionary);
......
...@@ -39,92 +39,63 @@ the use of this software, even if advised of the possibility of such damage. ...@@ -39,92 +39,63 @@ the use of this software, even if advised of the possibility of such damage.
#include <opencv2/highgui.hpp> #include <opencv2/highgui.hpp>
#include <opencv2/aruco.hpp> #include <opencv2/aruco.hpp>
#include <iostream>
using namespace std;
using namespace cv; using namespace cv;
namespace {
/** const char* about = "Create an ArUco grid board image";
*/ const char* keys =
static void help() { "{@outfile |<none> | Output image }"
cout << "Create an ArUco grid board image" << endl; "{w | | Number of markers in X direction }"
cout << "Parameters: " << endl; "{h | | Number of markers in Y direction }"
cout << "-o <image> # Output image" << endl; "{l | | Marker side lenght (in pixels) }"
cout << "-w <nmarkers> # Number of markers in X direction" << endl; "{s | | Separation between two consecutive markers in the grid (in pixels)}"
cout << "-h <nmarkers> # Number of markers in Y direction" << endl; "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "-l <markerLength> # Marker side lenght (in pixels)" << endl; "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
cout << "-s <markerSeparation> # Separation between two consecutive" "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<< "markers in the grid (in pixels)" << endl; "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "{m | | Margins size (in pixels). Default is marker separation (-s) }"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "{bb | 1 | Number of bits in marker borders }"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{si | false | show generated image }";
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl;
cout << "[-m <marginSize>] # Margins size (in pixels)"
<< "Default is marker separation" << endl;
cout << "[-bb <int>] # Number of bits in marker borders. Default is 1" << endl;
cout << "[-si] # show generated image" << endl;
} }
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
}
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
}
/**
*/
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(!isParam("-w", argc, argv) || !isParam("-h", argc, argv) || !isParam("-l", argc, argv) || if(argc < 7) {
!isParam("-s", argc, argv) || !isParam("-d", argc, argv) || !isParam("-o", argc, argv)) { parser.printMessage();
help();
return 0; return 0;
} }
int markersX = atoi(getParam("-w", argc, argv).c_str()); int markersX = parser.get<int>("w");
int markersY = atoi(getParam("-h", argc, argv).c_str()); int markersY = parser.get<int>("h");
int markerLength = atoi(getParam("-l", argc, argv).c_str()); int markerLength = parser.get<int>("l");
int markerSeparation = atoi(getParam("-s", argc, argv).c_str()); int markerSeparation = parser.get<int>("s");
int dictionaryId = atoi(getParam("-d", argc, argv).c_str()); int dictionaryId = parser.get<int>("d");
aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
int margins = markerSeparation; int margins = markerSeparation;
if(isParam("-m", argc, argv)) { if(parser.has("m")) {
margins = atoi(getParam("-m", argc, argv).c_str()); margins = parser.get<int>("m");
} }
int borderBits = 1; int borderBits = parser.get<int>("bb");
if(isParam("-bb", argc, argv)) { bool showImage = parser.get<bool>("si");
borderBits = atoi(getParam("-bb", argc, argv).c_str());
}
bool showImage = false; String out = parser.get<String>(0);
if(isParam("-si", argc, argv)) showImage = true;
if(!parser.check()) {
parser.printErrors();
return 0;
}
Size imageSize; Size imageSize;
imageSize.width = markersX * (markerLength + markerSeparation) - markerSeparation + 2 * margins; imageSize.width = markersX * (markerLength + markerSeparation) - markerSeparation + 2 * margins;
imageSize.height = imageSize.height =
markersY * (markerLength + markerSeparation) - markerSeparation + 2 * margins; markersY * (markerLength + markerSeparation) - markerSeparation + 2 * margins;
aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
aruco::GridBoard board = aruco::GridBoard::create(markersX, markersY, float(markerLength), aruco::GridBoard board = aruco::GridBoard::create(markersX, markersY, float(markerLength),
float(markerSeparation), dictionary); float(markerSeparation), dictionary);
...@@ -137,7 +108,7 @@ int main(int argc, char *argv[]) { ...@@ -137,7 +108,7 @@ int main(int argc, char *argv[]) {
waitKey(0); waitKey(0);
} }
imwrite(getParam("-o", argc, argv), boardImage); imwrite(out, boardImage);
return 0; return 0;
} }
...@@ -39,85 +39,57 @@ the use of this software, even if advised of the possibility of such damage. ...@@ -39,85 +39,57 @@ the use of this software, even if advised of the possibility of such damage.
#include <opencv2/highgui.hpp> #include <opencv2/highgui.hpp>
#include <opencv2/aruco/charuco.hpp> #include <opencv2/aruco/charuco.hpp>
#include <iostream>
using namespace std;
using namespace cv; using namespace cv;
namespace {
/** const char* about = "Create a ChArUco board image";
*/ const char* keys =
static void help() { "{@outfile |<none> | Output image }"
cout << "Create a ChArUco board image" << endl; "{w | | Number of squares in X direction }"
cout << "Parameters: " << endl; "{h | | Number of squares in Y direction }"
cout << "-o <image> # Output image" << endl; "{sl | | Square side lenght (in pixels) }"
cout << "-w <nsquares> # Number of squares in X direction" << endl; "{ml | | Marker side lenght (in pixels) }"
cout << "-h <nsquares> # Number of squares in Y direction" << endl; "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "-sl <squareLength> # Square side lenght (in pixels)" << endl; "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
cout << "-ml <markerLength> # Marker side lenght (in pixels)" << endl; "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "{m | | Margins size (in pixels). Default is (squareLength-markerLength) }"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{bb | 1 | Number of bits in marker borders }"
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl; "{si | false | show generated image }";
cout << "[-m <marginSize>] # Margins size (in pixels)"
<< "Default is (squareLength-markerLength)" << endl;
cout << "[-bb <int>] # Number of bits in marker borders. Default is 1" << endl;
cout << "[-si] # show generated image" << endl;
}
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
} }
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
}
/**
*/
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(!isParam("-w", argc, argv) || !isParam("-h", argc, argv) || !isParam("-sl", argc, argv) || if(argc < 7) {
!isParam("-ml", argc, argv) || !isParam("-d", argc, argv) || !isParam("-o", argc, argv)) { parser.printMessage();
help();
return 0; return 0;
} }
int squaresX = atoi(getParam("-w", argc, argv).c_str()); int squaresX = parser.get<int>("w");
int squaresY = atoi(getParam("-h", argc, argv).c_str()); int squaresY = parser.get<int>("h");
int squareLength = atoi(getParam("-sl", argc, argv).c_str()); int squareLength = parser.get<int>("sl");
int markerLength = atoi(getParam("-ml", argc, argv).c_str()); int markerLength = parser.get<int>("ml");
int dictionaryId = atoi(getParam("-d", argc, argv).c_str()); int dictionaryId = parser.get<int>("d");
aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
int margins = squareLength - markerLength; int margins = squareLength - markerLength;
if(isParam("-m", argc, argv)) { if(parser.has("m")) {
margins = atoi(getParam("-m", argc, argv).c_str()); margins = parser.get<int>("m");
} }
int borderBits = 1; int borderBits = parser.get<int>("bb");
if(isParam("-bb", argc, argv)) { bool showImage = parser.get<bool>("si");
borderBits = atoi(getParam("-bb", argc, argv).c_str());
String out = parser.get<String>(0);
if(!parser.check()) {
parser.printErrors();
return 0;
} }
bool showImage = false; aruco::Dictionary dictionary =
if(isParam("-si", argc, argv)) showImage = true; aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
Size imageSize; Size imageSize;
imageSize.width = squaresX * squareLength + 2 * margins; imageSize.width = squaresX * squareLength + 2 * margins;
...@@ -135,7 +107,7 @@ int main(int argc, char *argv[]) { ...@@ -135,7 +107,7 @@ int main(int argc, char *argv[]) {
waitKey(0); waitKey(0);
} }
imwrite(getParam("-o", argc, argv), boardImage); imwrite(out, boardImage);
return 0; return 0;
} }
...@@ -45,65 +45,50 @@ the use of this software, even if advised of the possibility of such damage. ...@@ -45,65 +45,50 @@ the use of this software, even if advised of the possibility of such damage.
using namespace std; using namespace std;
using namespace cv; using namespace cv;
namespace {
/** const char* about = "Create a ChArUco marker image";
*/ const char* keys =
static void help() { "{@outfile |<none> | Output image }"
cout << "Create a ChArUco marker image" << endl; "{sl | | Square side lenght (in pixels) }"
cout << "Parameters: " << endl; "{ml | | Marker side lenght (in pixels) }"
cout << "-o <image> # Output image" << endl; "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "-sl <squareLength> # Square side lenght (in pixels)" << endl; "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
cout << "-ml <markerLength> # Marker side lenght (in pixels)" << endl; "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "{ids |<none> | Four ids for the ChArUco marker: id1,id2,id3,id4 }"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{m | 0 | Margins size (in pixels) }"
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl; "{bb | 1 | Number of bits in marker borders }"
cout << "-ids <id1,id2,id3,id4> # Four ids for the ChArUco marker" << endl; "{si | false | show generated image }";
cout << "[-m <marginSize>] # Margins size (in pixels). Default is 0" << endl;
cout << "[-bb <int>] # Number of bits in marker borders. Default is 1" << endl;
cout << "[-si] # show generated image" << endl;
}
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
}
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
} }
/** /**
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(argc < 4) {
parser.printMessage();
return 0;
}
if(!isParam("-sl", argc, argv) || !isParam("-ml", argc, argv) || !isParam("-d", argc, argv) || int squareLength = parser.get<int>("sl");
!isParam("-ids", argc, argv)) { int markerLength = parser.get<int>("ml");
help(); int dictionaryId = parser.get<int>("d");
string idsString = parser.get<string>("ids");
int margins = parser.get<int>("m");
int borderBits = parser.get<int>("bb");
bool showImage = parser.get<bool>("si");
String out = parser.get<String>(0);
if(!parser.check()) {
parser.printErrors();
return 0; return 0;
} }
int squareLength = atoi(getParam("-sl", argc, argv).c_str());
int markerLength = atoi(getParam("-ml", argc, argv).c_str());
int dictionaryId = atoi(getParam("-d", argc, argv).c_str());
aruco::Dictionary dictionary = aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId)); aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
string idsString = getParam("-ids", argc, argv);
istringstream ss(idsString); istringstream ss(idsString);
vector< string > splittedIds; vector< string > splittedIds;
string token; string token;
...@@ -111,26 +96,13 @@ int main(int argc, char *argv[]) { ...@@ -111,26 +96,13 @@ int main(int argc, char *argv[]) {
splittedIds.push_back(token); splittedIds.push_back(token);
if(splittedIds.size() < 4) { if(splittedIds.size() < 4) {
cerr << "Incorrect ids format" << endl; cerr << "Incorrect ids format" << endl;
help(); parser.printMessage();
return 0; return 0;
} }
Vec4i ids; Vec4i ids;
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
ids[i] = atoi(splittedIds[i].c_str()); ids[i] = atoi(splittedIds[i].c_str());
int margins = 0;
if(isParam("-m", argc, argv)) {
margins = atoi(getParam("-m", argc, argv).c_str());
}
int borderBits = 1;
if(isParam("-bb", argc, argv)) {
borderBits = atoi(getParam("-bb", argc, argv).c_str());
}
bool showImage = false;
if(isParam("-si", argc, argv)) showImage = true;
Mat markerImg; Mat markerImg;
aruco::drawCharucoDiamond(dictionary, ids, squareLength, markerLength, markerImg, margins, aruco::drawCharucoDiamond(dictionary, ids, squareLength, markerLength, markerImg, margins,
borderBits); borderBits);
...@@ -140,7 +112,7 @@ int main(int argc, char *argv[]) { ...@@ -140,7 +112,7 @@ int main(int argc, char *argv[]) {
waitKey(0); waitKey(0);
} }
imwrite(getParam("-o", argc, argv), markerImg); imwrite(out, markerImg);
return 0; return 0;
} }
...@@ -39,78 +39,48 @@ the use of this software, even if advised of the possibility of such damage. ...@@ -39,78 +39,48 @@ the use of this software, even if advised of the possibility of such damage.
#include <opencv2/highgui.hpp> #include <opencv2/highgui.hpp>
#include <opencv2/aruco.hpp> #include <opencv2/aruco.hpp>
#include <iostream>
using namespace std;
using namespace cv; using namespace cv;
namespace {
/** const char* about = "Create an ArUco marker image";
*/ const char* keys =
static void help() { "{@outfile |<none> | Output image }"
cout << "Create an ArUco marker image" << endl; "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "Parameters: " << endl; "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
cout << "-o <image> # Output image" << endl; "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "{id | | Marker id in the dictionary }"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{ms | 200 | Marker size in pixels }"
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl; "{bb | 1 | Number of bits in marker borders }"
cout << "-id <int> # Marker id in the dictionary" << endl; "{si | false | show generated image }";
cout << "[-ms <int>] # Marker size in pixels. Default is 200" << endl;
cout << "[-bb <int>] # Number of bits in marker borders. Default is 1" << endl;
cout << "[-si] # show generated image" << endl;
}
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
}
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
} }
/**
*/
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(!isParam("-d", argc, argv) || !isParam("-o", argc, argv)) { if(argc < 4) {
help(); parser.printMessage();
return 0; return 0;
} }
int dictionaryId = atoi(getParam("-d", argc, argv).c_str()); int dictionaryId = parser.get<int>("d");
aruco::Dictionary dictionary = int markerId = parser.get<int>("id");
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId)); int borderBits = parser.get<int>("bb");
int markerSize = parser.get<int>("ms");
bool showImage = parser.get<bool>("si");
int markerId = atoi(getParam("-id", argc, argv).c_str()); String out = parser.get<String>(0);
int borderBits = 1;
if(isParam("-bb", argc, argv)) {
borderBits = atoi(getParam("-bb", argc, argv).c_str());
}
int markerSize = 200; if(!parser.check()) {
if(isParam("-ms", argc, argv)) { parser.printErrors();
markerSize = atoi(getParam("-ms", argc, argv).c_str()); return 0;
} }
bool showImage = false; aruco::Dictionary dictionary =
if(isParam("-si", argc, argv)) showImage = true; aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
Mat markerImg; Mat markerImg;
aruco::drawMarker(dictionary, markerId, markerSize, markerImg, borderBits); aruco::drawMarker(dictionary, markerId, markerSize, markerImg, borderBits);
...@@ -120,7 +90,7 @@ int main(int argc, char *argv[]) { ...@@ -120,7 +90,7 @@ int main(int argc, char *argv[]) {
waitKey(0); waitKey(0);
} }
imwrite(getParam("-o", argc, argv), markerImg); imwrite(out, markerImg);
return 0; return 0;
} }
...@@ -45,52 +45,25 @@ the use of this software, even if advised of the possibility of such damage. ...@@ -45,52 +45,25 @@ the use of this software, even if advised of the possibility of such damage.
using namespace std; using namespace std;
using namespace cv; using namespace cv;
namespace {
/** const char* about = "Pose estimation using a ArUco Planar Grid board";
*/ const char* keys =
static void help() { "{w | | Number of squares in X direction }"
cout << "Pose estimation using a ArUco Planar Grid board" << endl; "{h | | Number of squares in Y direction }"
cout << "Parameters: " << endl; "{l | | Marker side lenght (in pixels) }"
cout << "-w <nmarkers> # Number of markers in X direction" << endl; "{s | | Separation between two consecutive markers in the grid (in pixels)}"
cout << "-h <nmarkers> # Number of markers in Y direction" << endl; "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "-l <markerLength> # Marker side lenght (in meters)" << endl; "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
cout << "-s <markerSeparation> # Separation between two consecutive" "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<< "markers in the grid (in meters)" << endl; "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "{c | | Output file with calibrated camera parameters }"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "{v | | Input from video file, if ommited, input comes from camera }"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{ci | 0 | Camera id if input doesnt come from video (-v) }"
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl; "{dp | | File of marker detector parameters }"
cout << "-c <cameraParams> # Camera intrinsic parameters file" << endl; "{rs | | Apply refind strategy }"
cout << "[-v <videoFile>] # Input from video file, if ommited, input comes from camera" << endl; "{r | | show rejected candidates too }";
cout << "[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0" << endl;
cout << "[-dp <detectorParams>] # File of marker detector parameters" << endl;
cout << "[-rs] # Apply refind strategy" << endl;
cout << "[-r] # show rejected candidates too" << endl;
}
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
} }
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
}
/** /**
*/ */
static bool readCameraParameters(string filename, Mat &camMatrix, Mat &distCoeffs) { static bool readCameraParameters(string filename, Mat &camMatrix, Mat &distCoeffs) {
...@@ -137,27 +110,27 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p ...@@ -137,27 +110,27 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p
/** /**
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(!isParam("-w", argc, argv) || !isParam("-h", argc, argv) || !isParam("-l", argc, argv) || if(argc < 7) {
!isParam("-s", argc, argv) || !isParam("-d", argc, argv) || !isParam("-c", argc, argv)) { parser.printMessage();
help();
return 0; return 0;
} }
int markersX = atoi(getParam("-w", argc, argv).c_str()); int markersX = parser.get<int>("w");
int markersY = atoi(getParam("-h", argc, argv).c_str()); int markersY = parser.get<int>("h");
float markerLength = (float)atof(getParam("-l", argc, argv).c_str()); float markerLength = parser.get<float>("l");
float markerSeparation = (float)atof(getParam("-s", argc, argv).c_str()); float markerSeparation = parser.get<float>("s");
int dictionaryId = atoi(getParam("-d", argc, argv).c_str()); int dictionaryId = parser.get<int>("d");
aruco::Dictionary dictionary = bool showRejected = parser.has("r");
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId)); bool refindStrategy = parser.has("rs");
int camId = parser.get<int>("ci");
bool showRejected = false;
if(isParam("-r", argc, argv)) showRejected = true;
Mat camMatrix, distCoeffs; Mat camMatrix, distCoeffs;
if(isParam("-c", argc, argv)) { if(parser.has("c")) {
bool readOk = readCameraParameters(getParam("-c", argc, argv), camMatrix, distCoeffs); bool readOk = readCameraParameters(parser.get<string>("c"), camMatrix, distCoeffs);
if(!readOk) { if(!readOk) {
cerr << "Invalid camera file" << endl; cerr << "Invalid camera file" << endl;
return 0; return 0;
...@@ -165,8 +138,8 @@ int main(int argc, char *argv[]) { ...@@ -165,8 +138,8 @@ int main(int argc, char *argv[]) {
} }
aruco::DetectorParameters detectorParams; aruco::DetectorParameters detectorParams;
if(isParam("-dp", argc, argv)) { if(parser.has("dp")) {
bool readOk = readDetectorParameters(getParam("-dp", argc, argv), detectorParams); bool readOk = readDetectorParameters(parser.get<string>("dp"), detectorParams);
if(!readOk) { if(!readOk) {
cerr << "Invalid detector parameters file" << endl; cerr << "Invalid detector parameters file" << endl;
return 0; return 0;
...@@ -174,17 +147,25 @@ int main(int argc, char *argv[]) { ...@@ -174,17 +147,25 @@ int main(int argc, char *argv[]) {
} }
detectorParams.doCornerRefinement = true; // do corner refinement in markers detectorParams.doCornerRefinement = true; // do corner refinement in markers
bool refindStrategy = false; String video;
if(isParam("-rs", argc, argv)) refindStrategy = true; if(parser.has("v")) {
video = parser.get<String>("v");
}
if(!parser.check()) {
parser.printErrors();
return 0;
}
aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
VideoCapture inputVideo; VideoCapture inputVideo;
int waitTime; int waitTime;
if(isParam("-v", argc, argv)) { if(!video.empty()) {
inputVideo.open(getParam("-v", argc, argv)); inputVideo.open(video);
waitTime = 0; waitTime = 0;
} else { } else {
int camId = 0;
if(isParam("-ci", argc, argv)) camId = atoi(getParam("-ci", argc, argv).c_str());
inputVideo.open(camId); inputVideo.open(camId);
waitTime = 10; waitTime = 10;
} }
......
...@@ -46,50 +46,25 @@ using namespace std; ...@@ -46,50 +46,25 @@ using namespace std;
using namespace cv; using namespace cv;
/** namespace {
*/ const char* about = "Pose estimation using a ChArUco board";
static void help() { const char* keys =
cout << "Pose estimation using a ChArUco board" << endl; "{w | | Number of squares in X direction }"
cout << "Parameters: " << endl; "{h | | Number of squares in Y direction }"
cout << "-w <nmarkers> # Number of markers in X direction" << endl; "{sl | | Square side lenght (in pixels) }"
cout << "-h <nsquares> # Number of squares in Y direction" << endl; "{ml | | Marker side lenght (in pixels) }"
cout << "-sl <squareLength> # Square side lenght (in meters)" << endl; "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "-ml <markerLength> # Marker side lenght (in meters)" << endl; "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{c | | Output file with calibrated camera parameters }"
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl; "{v | | Input from video file, if ommited, input comes from camera }"
cout << "[-c <cameraParams>] # Camera intrinsic parameters file" << endl; "{ci | 0 | Camera id if input doesnt come from video (-v) }"
cout << "[-v <videoFile>] # Input from video file, if ommited, input comes from camera" << endl; "{dp | | File of marker detector parameters }"
cout << "[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0" << endl; "{rs | | Apply refind strategy }"
cout << "[-dp <detectorParams>] # File of marker detector parameters" << endl; "{r | | show rejected candidates too }";
cout << "[-rs] # Apply refind strategy" << endl;
cout << "[-r] # show rejected candidates too" << endl;
}
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
}
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
} }
/** /**
*/ */
static bool readCameraParameters(string filename, Mat &camMatrix, Mat &distCoeffs) { static bool readCameraParameters(string filename, Mat &camMatrix, Mat &distCoeffs) {
...@@ -135,27 +110,31 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p ...@@ -135,27 +110,31 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p
/** /**
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(!isParam("-w", argc, argv) || !isParam("-h", argc, argv) || !isParam("-sl", argc, argv) || if(argc < 6) {
!isParam("-ml", argc, argv) || !isParam("-d", argc, argv)) { parser.printMessage();
help();
return 0; return 0;
} }
int squaresX = atoi(getParam("-w", argc, argv).c_str()); int squaresX = parser.get<int>("w");
int squaresY = atoi(getParam("-h", argc, argv).c_str()); int squaresY = parser.get<int>("h");
float squareLength = (float)atof(getParam("-sl", argc, argv).c_str()); float squareLength = parser.get<float>("sl");
float markerLength = (float)atof(getParam("-ml", argc, argv).c_str()); float markerLength = parser.get<float>("ml");
int dictionaryId = atoi(getParam("-d", argc, argv).c_str()); int dictionaryId = parser.get<int>("d");
aruco::Dictionary dictionary = bool showRejected = parser.has("r");
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId)); bool refindStrategy = parser.has("rs");
int camId = parser.get<int>("ci");
bool showRejected = false;
if(isParam("-r", argc, argv)) showRejected = true; String video;
if(parser.has("v")) {
video = parser.get<String>("v");
}
Mat camMatrix, distCoeffs; Mat camMatrix, distCoeffs;
if(isParam("-c", argc, argv)) { if(parser.has("c")) {
bool readOk = readCameraParameters(getParam("-c", argc, argv), camMatrix, distCoeffs); bool readOk = readCameraParameters(parser.get<string>("c"), camMatrix, distCoeffs);
if(!readOk) { if(!readOk) {
cerr << "Invalid camera file" << endl; cerr << "Invalid camera file" << endl;
return 0; return 0;
...@@ -163,25 +142,28 @@ int main(int argc, char *argv[]) { ...@@ -163,25 +142,28 @@ int main(int argc, char *argv[]) {
} }
aruco::DetectorParameters detectorParams; aruco::DetectorParameters detectorParams;
if(isParam("-dp", argc, argv)) { if(parser.has("dp")) {
bool readOk = readDetectorParameters(getParam("-dp", argc, argv), detectorParams); bool readOk = readDetectorParameters(parser.get<string>("dp"), detectorParams);
if(!readOk) { if(!readOk) {
cerr << "Invalid detector parameters file" << endl; cerr << "Invalid detector parameters file" << endl;
return 0; return 0;
} }
} }
bool refindStrategy = false; if(!parser.check()) {
if(isParam("-rs", argc, argv)) refindStrategy = true; parser.printErrors();
return 0;
}
aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
VideoCapture inputVideo; VideoCapture inputVideo;
int waitTime; int waitTime;
if(isParam("-v", argc, argv)) { if(!video.empty()) {
inputVideo.open(getParam("-v", argc, argv)); inputVideo.open(video);
waitTime = 0; waitTime = 0;
} else { } else {
int camId = 0;
if(isParam("-ci", argc, argv)) camId = atoi(getParam("-ci", argc, argv).c_str());
inputVideo.open(camId); inputVideo.open(camId);
waitTime = 10; waitTime = 10;
} }
...@@ -251,7 +233,7 @@ int main(int argc, char *argv[]) { ...@@ -251,7 +233,7 @@ int main(int argc, char *argv[]) {
if(interpolatedCorners > 0) { if(interpolatedCorners > 0) {
Scalar color; Scalar color;
color = Scalar(0, 0, 255); color = Scalar(255, 0, 0);
aruco::drawDetectedCornersCharuco(imageCopy, charucoCorners, charucoIds, color); aruco::drawDetectedCornersCharuco(imageCopy, charucoCorners, charucoIds, color);
} }
......
...@@ -46,51 +46,26 @@ using namespace std; ...@@ -46,51 +46,26 @@ using namespace std;
using namespace cv; using namespace cv;
/** namespace {
*/ const char* about = "Detect ChArUco markers";
static void help() { const char* keys =
cout << "Detect ChArUco markers" << endl; "{sl | | Square side lenght (in pixels) }"
cout << "Parameters: " << endl; "{ml | | Marker side lenght (in pixels) }"
cout << "-sl <squareLength> # Square side lenght (in meters)" << endl; "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "-ml <markerLength> # Marker side lenght (in meters)" << endl; "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{c | | Output file with calibrated camera parameters }"
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl; "{as | | Automatic scale. The provided number is multiplied by the last"
cout << "[-c <cameraParams>] # Camera intrinsic parameters file" << endl; "diamond id becoming an indicator of the square length. In this case, the -sl and "
cout << "[-as <float>] # Automatic scale. The provided number is multiplied by the last " "-ml are only used to know the relative length relation between squares and markers }"
<< "diamond id becoming an indicator of the square length. In this case, the -sl and " "{v | | Input from video file, if ommited, input comes from camera }"
<< "-ml are only used to know the relative length relation between " "{ci | 0 | Camera id if input doesnt come from video (-v) }"
<< "squares and markers" << endl; "{dp | | File of marker detector parameters }"
cout << "[-v <videoFile>] # Input from video file, if ommited, input comes from camera" << endl; "{rs | | Apply refind strategy }"
cout << "[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0" << endl; "{r | | show rejected candidates too }";
cout << "[-dp <detectorParams>] # File of marker detector parameters" << endl;
cout << "[-r] # show rejected candidates too" << endl;
}
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
}
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
} }
/** /**
*/ */
static bool readCameraParameters(string filename, Mat &camMatrix, Mat &distCoeffs) { static bool readCameraParameters(string filename, Mat &camMatrix, Mat &distCoeffs) {
...@@ -136,56 +111,61 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p ...@@ -136,56 +111,61 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p
/** /**
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(!isParam("-sl", argc, argv) || !isParam("-ml", argc, argv) || !isParam("-d", argc, argv)) { if(argc < 4) {
help(); parser.printMessage();
return 0; return 0;
} }
float squareLength = (float)atof(getParam("-sl", argc, argv).c_str()); float squareLength = parser.get<float>("sl");
float markerLength = (float)atof(getParam("-ml", argc, argv).c_str()); float markerLength = parser.get<float>("ml");
int dictionaryId = atoi(getParam("-d", argc, argv).c_str()); int dictionaryId = parser.get<int>("d");
aruco::Dictionary dictionary = bool showRejected = parser.has("r");
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId)); bool estimatePose = parser.has("c");
bool autoScale = parser.has("as");
bool showRejected = false; float autoScaleFactor = autoScale ? parser.get<float>("as") : 1.f;
if(isParam("-r", argc, argv)) showRejected = true;
bool estimatePose = false; aruco::DetectorParameters detectorParams;
Mat camMatrix, distCoeffs; if(parser.has("dp")) {
if(isParam("-c", argc, argv)) { bool readOk = readDetectorParameters(parser.get<string>("dp"), detectorParams);
bool readOk = readCameraParameters(getParam("-c", argc, argv), camMatrix, distCoeffs);
if(!readOk) { if(!readOk) {
cerr << "Invalid camera file" << endl; cerr << "Invalid detector parameters file" << endl;
return 0; return 0;
} }
estimatePose = true;
} }
bool autoScale = false; int camId = parser.get<int>("ci");
float autoScaleFactor = 1.; String video;
if(isParam("-as", argc, argv)) {
autoScaleFactor = (float)atof(getParam("-as", argc, argv).c_str()); if(parser.has("v")) {
autoScale = true; video = parser.get<String>("v");
} }
aruco::DetectorParameters detectorParams; if(!parser.check()) {
if(isParam("-dp", argc, argv)) { parser.printErrors();
bool readOk = readDetectorParameters(getParam("-dp", argc, argv), detectorParams); return 0;
}
aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
Mat camMatrix, distCoeffs;
if(estimatePose) {
bool readOk = readCameraParameters(parser.get<string>("c"), camMatrix, distCoeffs);
if(!readOk) { if(!readOk) {
cerr << "Invalid detector parameters file" << endl; cerr << "Invalid camera file" << endl;
return 0; return 0;
} }
} }
VideoCapture inputVideo; VideoCapture inputVideo;
int waitTime; int waitTime;
if(isParam("-v", argc, argv)) { if(!video.empty()) {
inputVideo.open(getParam("-v", argc, argv)); inputVideo.open(video);
waitTime = 0; waitTime = 0;
} else { } else {
int camId = 0;
if(isParam("-ci", argc, argv)) camId = atoi(getParam("-ci", argc, argv).c_str());
inputVideo.open(camId); inputVideo.open(camId);
waitTime = 10; waitTime = 10;
} }
...@@ -224,7 +204,7 @@ int main(int argc, char *argv[]) { ...@@ -224,7 +204,7 @@ int main(int argc, char *argv[]) {
for(unsigned int i = 0; i < diamondCorners.size(); i++) { for(unsigned int i = 0; i < diamondCorners.size(); i++) {
float autoSquareLength = autoScaleFactor * float(diamondIds[i].val[3]); float autoSquareLength = autoScaleFactor * float(diamondIds[i].val[3]);
vector< vector< Point2f > > currentCorners; vector< vector< Point2f > > currentCorners;
vector< Mat > currentRvec, currentTvec; vector< Vec3d > currentRvec, currentTvec;
currentCorners.push_back(diamondCorners[i]); currentCorners.push_back(diamondCorners[i]);
aruco::estimatePoseSingleMarkers(currentCorners, autoSquareLength, camMatrix, aruco::estimatePoseSingleMarkers(currentCorners, autoSquareLength, camMatrix,
distCoeffs, currentRvec, currentTvec); distCoeffs, currentRvec, currentTvec);
......
...@@ -39,56 +39,26 @@ the use of this software, even if advised of the possibility of such damage. ...@@ -39,56 +39,26 @@ the use of this software, even if advised of the possibility of such damage.
#include <opencv2/highgui.hpp> #include <opencv2/highgui.hpp>
#include <opencv2/aruco.hpp> #include <opencv2/aruco.hpp>
#include <vector>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
using namespace cv; using namespace cv;
namespace {
/** const char* about = "Basic marker detection";
*/ const char* keys =
static void help() { "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
cout << "Basic marker detection" << endl; "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
cout << "Parameters: " << endl; "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
cout << "-d <dictionary> # DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, " "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
<< "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, " "{v | | Input from video file, if ommited, input comes from camera }"
<< "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12," "{ci | 0 | Camera id if input doesnt come from video (-v) }"
<< "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16" << endl; "{c | | Camera intrinsic parameters. Needed for camera pose }"
cout << "[-v <videoFile>] # Input from video file, if ommited, input comes from camera" << endl; "{l | 0.1 | Marker side lenght (in meters). Needed for correct scale in camera pose }"
cout << "[-ci <int>] # Camera id if input doesnt come from video (-v). Default is 0" << endl; "{dp | | File of marker detector parameters }"
cout << "[-c <cameraParams>] # Camera intrinsic parameters. Needed for camera pose" << endl; "{r | | show rejected candidates too }";
cout << "[-l <markerLength>] # Marker side lenght (in meters). Needed for correct"
<< "scale in camera pose, default 0.1" << endl;
cout << "[-dp <detectorParams>] # File of marker detector parameters" << endl;
cout << "[-r] # show rejected candidates too" << endl;
}
/**
*/
static bool isParam(string param, int argc, char **argv) {
for(int i = 0; i < argc; i++)
if(string(argv[i]) == param) return true;
return false;
} }
/**
*/
static string getParam(string param, int argc, char **argv, string defvalue = "") {
int idx = -1;
for(int i = 0; i < argc && idx == -1; i++)
if(string(argv[i]) == param) idx = i;
if(idx == -1 || (idx + 1) >= argc)
return defvalue;
else
return argv[idx + 1];
}
/** /**
*/ */
static bool readCameraParameters(string filename, Mat &camMatrix, Mat &distCoeffs) { static bool readCameraParameters(string filename, Mat &camMatrix, Mat &distCoeffs) {
...@@ -136,49 +106,59 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p ...@@ -136,49 +106,59 @@ static bool readDetectorParameters(string filename, aruco::DetectorParameters &p
/** /**
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if(!isParam("-d", argc, argv)) { if(argc < 2) {
help(); parser.printMessage();
return 0; return 0;
} }
int dictionaryId = atoi(getParam("-d", argc, argv).c_str()); int dictionaryId = parser.get<int>("d");
aruco::Dictionary dictionary = bool showRejected = parser.has("r");
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId)); bool estimatePose = parser.has("c");
float markerLength = parser.get<float>("l");
bool showRejected = false;
if(isParam("-r", argc, argv)) showRejected = true;
bool estimatePose = false; aruco::DetectorParameters detectorParams;
Mat camMatrix, distCoeffs; if(parser.has("dp")) {
if(isParam("-c", argc, argv)) { bool readOk = readDetectorParameters(parser.get<string>("dp"), detectorParams);
bool readOk = readCameraParameters(getParam("-c", argc, argv), camMatrix, distCoeffs);
if(!readOk) { if(!readOk) {
cerr << "Invalid camera file" << endl; cerr << "Invalid detector parameters file" << endl;
return 0; return 0;
} }
estimatePose = true;
} }
float markerLength = (float)atof(getParam("-l", argc, argv, "0.1").c_str()); detectorParams.doCornerRefinement = true; // do corner refinement in markers
int camId = parser.get<int>("ci");
String video;
if(parser.has("v")) {
video = parser.get<String>("v");
}
aruco::DetectorParameters detectorParams; if(!parser.check()) {
if(isParam("-dp", argc, argv)) { parser.printErrors();
bool readOk = readDetectorParameters(getParam("-dp", argc, argv), detectorParams); return 0;
}
aruco::Dictionary dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
Mat camMatrix, distCoeffs;
if(estimatePose) {
bool readOk = readCameraParameters(parser.get<string>("c"), camMatrix, distCoeffs);
if(!readOk) { if(!readOk) {
cerr << "Invalid detector parameters file" << endl; cerr << "Invalid camera file" << endl;
return 0; return 0;
} }
} }
detectorParams.doCornerRefinement = true; // do corner refinement in markers
VideoCapture inputVideo; VideoCapture inputVideo;
int waitTime; int waitTime;
if(isParam("-v", argc, argv)) { if(!video.empty()) {
inputVideo.open(getParam("-v", argc, argv)); inputVideo.open(video);
waitTime = 0; waitTime = 0;
} else { } else {
int camId = 0;
if(isParam("-ci", argc, argv)) camId = atoi(getParam("-ci", argc, argv).c_str());
inputVideo.open(camId); inputVideo.open(camId);
waitTime = 10; waitTime = 10;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment