25 #include <Base/Image/Image.hh>
26 #include <Base/Image/ImageIO.hh>
27 #include <FeatureDetector/CheckerboardDetector.hh>
34 #include "Base/Common/getopt_W32.h"
51 cout <<
"Usage: biasextractcheckerboard -f Filename.m -x xnum -y ynum -d image1 image2 ..."<<endl
53 cout <<
" The tool tries to find checkerboards in the input images" << endl
54 <<
" finds corners also in fisheye distorted images and " << endl
55 <<
" writes these to the Matlab file 'Filename.m'." << endl
56 <<
" xnum and ynum are the number of the checkerboards inner corners."
58 <<
" -d writes debug images." << endl
59 <<
" Do not use .mip images since Matlab is unable to read them." << endl
64 int main(
int argc,
char *argv[])
67 string MatlabFilename =
"ExtractedCorners.m";
70 bool writedebug =
true;
74 c = char(getopt(argc,argv,
"f:x:y:hd"));
82 x_corners = atoi(optarg);
85 y_corners = atoi(optarg);
88 MatlabFilename = optarg;
101 if (argc-optind < 1) {
102 cout <<
"==> To few arguments."<<endl;
108 vector<string> filenames, bad_filenames;
109 vector<vector<pair<float,float> > > all_coords;
110 for (
int i=optind; i<argc; i++) {
112 if (ImageIO::Load(argv[i], img)!=0) {
113 BIASERR(
"Could not load "<<argv[i]); BIASBREAK;
116 std::vector< std::pair<float,float> > coords;
117 int result = CheckerboardDetector::Compute(img, x_corners, y_corners,
120 cout <<
"Sucess: " << argv[i]<< endl;
121 all_coords.push_back(coords);
122 filenames.push_back(argv[i]);
124 cout <<
"Failure: " << argv[i]<< endl;
125 bad_filenames.push_back(argv[i]);
129 ofstream ofs(MatlabFilename.c_str());
131 ofs <<
"numpoints = [" << x_corners <<
" " << y_corners <<
"];" << endl;
133 ofs <<
"imagenames = {";
134 for (
unsigned int i=0; i<filenames.size(); i++) {
135 ofs <<
"'" << filenames[i] <<
"' ";
139 if (bad_filenames.size()>0) {
140 ofs <<
"bad_imagenames = {";
141 for (
unsigned int i=0; i<bad_filenames.size(); i++) {
142 ofs <<
"'" << bad_filenames[i] <<
"' ";
148 for (
unsigned int i=0; i<all_coords.size(); i++) {
149 for (
unsigned int j=0; j<all_coords[i].size(); j++) {
150 ofs << (all_coords[i][j]).first <<
" ";
157 for (
unsigned int i=0; i<all_coords.size(); i++) {
158 for (
unsigned int j=0; j<all_coords[i].size(); j++) {
159 ofs << (all_coords[i][j]).second <<
" ";