Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCornerDetector.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  @example ExampleCornerDetector.cpp
27  @relates CornerDetectorFoerstner, CornerDetectorHarris, CornerDetectorKLT, CornerDetectorSusan
28  @brief Example for usage of CornerDetector
29  Usage: ExampleCornerDetector [parameter] <im1> <im2> [ <im3> ... ]
30  @ingroup g_examples
31  @author MIP
32 */
33 
34 #include <bias_config.h>
35 #include <FeatureDetector/CornerDetectorFoerstner.hh>
36 #include <FeatureDetector/CornerDetectorHarris.hh>
37 #include <FeatureDetector/CornerDetectorSusan.hh>
38 #include <FeatureDetector/CornerDetectorKLT.hh>
39 #include <FeatureDetector/LinearRegionDetector.hh>
40 #include <Base/Image/ColourRGB.hh>
41 #include <Base/ImageUtils/ImageDraw.hh>
42 #include <Base/Image/ImageConvert.hh>
43 #include <Base/Image/ImageIO.hh>
44 
45 using namespace BIAS;
46 using namespace std;
47 
48 #define type 1
49 #if type == 0
50 
51 #ifdef BUILD_IMAGE_INT
52 #define StorageType unsigned char
53 #define KernelType int
54 #else
55 #define StorageType unsigned char
56 #define KernelType float
57 #endif
58 
59 #elif type == 1
60 
61 #define StorageType float
62 #define KernelType float
63 
64 #endif
65 
66 void Draw(Image<unsigned char>& im, vector<HomgPoint2D>& p)
67 {
68  ColourRGB<unsigned char> col(0, 255, 0);
69  const int nump=p.size();
70  unsigned start[2];
71  unsigned radius=10;
72 
73  for (int l=0; l<nump; l++){
74  if (!p[l].IsAtInfinity()){
75  // circel around corner in actual image
76  start[0]=(unsigned)rint(p[l][0]);
77  start[1]=(unsigned)rint(p[l][1]);
78  ImageDraw<unsigned char>::Circle(im, start[0], start[1],
79  radius, col);
80  }
81  }
82 }
83 
84 int main(int argc, char *argv[])
85 {
87 #if type ==1
89 #endif
90 
91 #if type == 0
93  cds.SetMaxNumFeatures(1000);
94 #endif
98 
99  Image<unsigned char> ucim, rgbim;
101  vector<HomgPoint2D> p;
102  vector<QUAL> qual;
103 
104  int argind = 1;
105  if (argc-argind<1 || argind<1){
106  cerr << argv[0] << " [parameter] <im1> <im2> [ <im3> ... ] \n";
107  return -2;
108  }
109 
111 
112  switch (cdt){
114 #if type == 0
115  cd = &cds;
116 #else
117  BIASERR("susan only implemented for unsigned char");
118 #endif
119  break;
121  cd = &cdklt;
122  cout << "corner detector klt has been chosen " << endl;
123  cdklt.SetMinCornerness(400);
124 #if type ==1
125  cdg = &cdklt;
126 #endif
127  break;
129  cd = &cdh;
130  cout << "corner detector harris has been chosen " << endl;
131 #if type == 1
132  cdg = &cdh;
133 #endif
134  break;
136  cd = &cdf;
137 #if type == 1
138  cdg = &cdf;
139 #endif
140  break;
141  default:
142  BIASERR("unknown corner detector type");
143  BIASABORT
144  break;
145  }
146 
147  bool WantLinearRegionDetector = false;
148  if (WantLinearRegionDetector) {
149  cout << "CornerDetector not used, detecting LINEAR regions ..."<<endl;
151  cd = &cdl;
152  cd->AddDebugLevel(D_CD_WRITE_DEBUG_IM);
153  cd->AddDebugLevel(D_CD_FEATURES);
154  }
155 
156  for (int i=argind; i<argc; i++){
157 #if type == 0
158  if (ImageIO::Load(argv[i], im)!=0){
159 #else
160  if (ImageIO::Load(argv[i], ucim)!=0){
161 #endif
162  BIASERR("error loading image "<<argv[i]);
163  return -1;
164  } else {
165  cerr << "read "<<argv[i]<<endl;
166  }
167 
168  ImageBase tempimage;
169 
170 #if type == 0
172  im = tempimage;
173 #else
174  ImageConvert::Convert(ucim, tempimage, ImageBase::CM_Grey);
175  ucim = tempimage;
176 #endif
177 
178 
179 #if type != 0
180  if (ImageConvert::ConvertST(ucim, im, ImageBase::ST_float)!=0){
181  BIASERR("error converting image "<<argv[i]);
182  }
183  ImageIO::Save("fimage.mip", im);
184 #endif
185 
186 #if type == 0
187  if (cd->Detect(im, p, qual)!=0) {
188  cerr<<"Corner detector indicated an error !"<<endl;
189  }
190 #endif
191 
192 #if type == 1
193  if (cdg->Detect(im, p, qual)!=0) {
194  cerr<<"Corner detector indicated an error !"<<endl;
195  }
196 #endif
197 
198  cerr << "found "<<p.size()<<" corners"<<endl;
199 
200  for (unsigned int r=0; r<p.size(); r++) {
201  cout <<setw(5)<<r<<" : "<<p[r]<<" with quality "<<qual[r]<<endl;
202  }
203 
204 #if type == 0
206 #else
208 #endif
209  Draw(rgbim, p);
210 
211  ostringstream name;
212  name << "corners-"<<setw(4)<<setfill('0')<<i-argind<<".mip";
213  //ImageIO::Save(name.str(), rgbim);
214  ImageIO::Save(name.str(), rgbim);
215 
216  }
217 
218  return 0;
219 }
void AddDebugLevel(const long int lv)
Definition: Debug.hh:355
gray values, 1 channel
Definition: ImageBase.hh:130
Harris corner detector, detects grey value corners in images.
void SetMaxNumFeatures(const int maxnum)
static void Circle(BIAS::Image< StorageType > &dstImg, const int &centerX, const int &centerY, const int &radius=3, const BIAS::ColourRGB< StorageType > &colorRGB=ColourRGB< StorageType >(255, 255, 255), const int &thickness=1, const int &linetype=8, const int &shift=0)
OpenCV: Draws a circle.
Definition: ImageDraw.cpp:1512
float image storage type
Definition: ImageBase.hh:118
try to detect linear regions (const gradient) in images, experimental code for testing ...
foerstner corner detector, detects grey value corners in images
virtual void SetMinCornerness(double min_cornerness)
sets minimum cornernes of detectable features
virtual int Detect(const Image< StorageType > &image, std::vector< HomgPoint2D > &p, std::vector< QUAL > &quality)
purely virtual interface definition
The Susan corner detector (oxford implementation, see license)
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
Computes the cornerness as the smaller eigenvalue of the structure tensor matrix. ...
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
purly virtual interface defining class for corner detectors
static int Convert(BIAS::ImageBase &source, BIAS::ImageBase &dest, enum BIAS::ImageBase::EColorModel targetColorModel, bool bPlanar=false)
main general conversion function, calls desired specialized functions, always initializes the destIma...
base class for all gradient based corner detectors
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
virtual int Detect(const Image< StorageType > &image, std::vector< HomgPoint2D > &p, std::vector< QUAL > &quality, std::vector< Matrix2x2< double > > *cov=NULL)
detect corners in a grey image