Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCheckerboard.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 /**
27  @example ExampleCheckerboard.cpp
28  @relates CheckerboardDetector
29  @brief Example for usage of Checkerboard Detector
30  Usage: ExampleCheckerboard <filename> <inner_xCorners> <inner_yCorners>
31  @ingroup g_examples
32  @author MIP
33 */
34 
35 #include <Base/Common/W32Compat.hh>
36 #include <math.h>
37 #include <vector>
38 #include <string>
39 #include <iostream>
40 #include <Base/Debug/Error.hh>
41 #include <Base/Image/Image.hh>
42 #include <Base/Image/ImageIO.hh>
43 #include <Base/Common/FileHandling.hh>
44 #include <FeatureDetector/CheckerboardDetector.hh>
45 
46 using namespace std;
47 using namespace BIAS;
48 
49 int main(int argc, char** argv)
50 {
51  // params
52  string imgFilename(BIAS_TESTS_DATA "chess7x4_002.jpg");
53  unsigned int xCorners(7), yCorners(4); // inner corners
54 
55  // parse args
56  if (argc > 1)
57  imgFilename = argv[1];
58  if (argc > 2)
59  xCorners = atoi(argv[2]);
60  if (argc > 3)
61  yCorners = atoi(argv[3]);
62 
63  if (argc < 2)
64  cout << "Usage: ExampleCheckerboard [<image>] [<corners x>] [<corners y>]"
65  << endl << endl
66  << "Default: image " << imgFilename << " with 7 x 4 corners"
67  << endl << endl;
68  else
69  cout << "Detecting " << xCorners << "x " << yCorners << " corners in image "
70  << imgFilename << endl << endl;
71 
72  cout << "Loading image " << imgFilename << endl;
74  if (ImageIO::Load(imgFilename, img)!=0)
75  {
76  cout << "Failed to load image " << imgFilename << "!" << endl;
77  return -1;
78  }
79 
80  // storage for detected positions (resizing is done by CheckerboardDetector::Compute)
81  vector< pair<float,float> > coords;
82 
83  // detect chessboard corners
84  int result = CheckerboardDetector::Compute(img, xCorners , yCorners, coords, true);
85  if (result != 0){
86  cout << "Failed to detect corners!" << endl;
87  return -1;
88  }
89 
90  // print result corners
91  cout << "Detected " << coords.size() << " corners : " << endl;
92  for (unsigned int i = 0; i < coords.size(); i++) {
93  cout << "[" << (i+1) << "] corner " << coords[i].first << ", " << coords[i].second
94  << endl;
95  }
96  cout << endl;
97 
98  return 0;
99 }
100