Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCheckerboard.cpp

Example for usage of Checkerboard Detector Usage: ExampleCheckerboard <filename> <inner_xCorners> <inner_yCorners>

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleCheckerboard.cpp
@relates CheckerboardDetector
@brief Example for usage of Checkerboard Detector
Usage: ExampleCheckerboard <filename> <inner_xCorners> <inner_yCorners>
@ingroup g_examples
@author MIP
*/
#include <Base/Common/W32Compat.hh>
#include <math.h>
#include <vector>
#include <string>
#include <iostream>
#include <Base/Debug/Error.hh>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Common/FileHandling.hh>
#include <FeatureDetector/CheckerboardDetector.hh>
using namespace std;
using namespace BIAS;
int main(int argc, char** argv)
{
// params
string imgFilename(BIAS_TESTS_DATA "chess7x4_002.jpg");
unsigned int xCorners(7), yCorners(4); // inner corners
// parse args
if (argc > 1)
imgFilename = argv[1];
if (argc > 2)
xCorners = atoi(argv[2]);
if (argc > 3)
yCorners = atoi(argv[3]);
if (argc < 2)
cout << "Usage: ExampleCheckerboard [<image>] [<corners x>] [<corners y>]"
<< endl << endl
<< "Default: image " << imgFilename << " with 7 x 4 corners"
<< endl << endl;
else
cout << "Detecting " << xCorners << "x " << yCorners << " corners in image "
<< imgFilename << endl << endl;
cout << "Loading image " << imgFilename << endl;
if (ImageIO::Load(imgFilename, img)!=0)
{
cout << "Failed to load image " << imgFilename << "!" << endl;
return -1;
}
// storage for detected positions (resizing is done by CheckerboardDetector::Compute)
vector< pair<float,float> > coords;
// detect chessboard corners
int result = CheckerboardDetector::Compute(img, xCorners , yCorners, coords, true);
if (result != 0){
cout << "Failed to detect corners!" << endl;
return -1;
}
// print result corners
cout << "Detected " << coords.size() << " corners : " << endl;
for (unsigned int i = 0; i < coords.size(); i++) {
cout << "[" << (i+1) << "] corner " << coords[i].first << ", " << coords[i].second
<< endl;
}
cout << endl;
return 0;
}