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

Example for usage of CornerDetector Usage: ExampleCornerDetector [parameter] <im1> <im2> [ <im3> ... ]

, CornerDetectorHarris, CornerDetectorKLT, CornerDetectorSusan

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 ExampleCornerDetector.cpp
@relates CornerDetectorFoerstner, CornerDetectorHarris, CornerDetectorKLT, CornerDetectorSusan
@brief Example for usage of CornerDetector
Usage: ExampleCornerDetector [parameter] <im1> <im2> [ <im3> ... ]
@ingroup g_examples
@author MIP
*/
#include <bias_config.h>
#include <FeatureDetector/CornerDetectorFoerstner.hh>
#include <FeatureDetector/CornerDetectorHarris.hh>
#include <FeatureDetector/CornerDetectorSusan.hh>
#include <FeatureDetector/CornerDetectorKLT.hh>
#include <FeatureDetector/LinearRegionDetector.hh>
#include <Base/Image/ColourRGB.hh>
#include <Base/ImageUtils/ImageDraw.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Image/ImageIO.hh>
using namespace BIAS;
using namespace std;
#define type 1
#if type == 0
#ifdef BUILD_IMAGE_INT
#define StorageType unsigned char
#define KernelType int
#else
#define StorageType unsigned char
#define KernelType float
#endif
#elif type == 1
#define StorageType float
#define KernelType float
#endif
void Draw(Image<unsigned char>& im, vector<HomgPoint2D>& p)
{
ColourRGB<unsigned char> col(0, 255, 0);
const int nump=p.size();
unsigned start[2];
unsigned radius=10;
for (int l=0; l<nump; l++){
if (!p[l].IsAtInfinity()){
// circel around corner in actual image
start[0]=(unsigned)rint(p[l][0]);
start[1]=(unsigned)rint(p[l][1]);
ImageDraw<unsigned char>::Circle(im, start[0], start[1],
radius, col);
}
}
}
int main(int argc, char *argv[])
{
#if type ==1
#endif
#if type == 0
cds.SetMaxNumFeatures(1000);
#endif
Image<unsigned char> ucim, rgbim;
vector<HomgPoint2D> p;
vector<QUAL> qual;
int argind = 1;
if (argc-argind<1 || argind<1){
cerr << argv[0] << " [parameter] <im1> <im2> [ <im3> ... ] \n";
return -2;
}
switch (cdt){
#if type == 0
cd = &cds;
#else
BIASERR("susan only implemented for unsigned char");
#endif
break;
cd = &cdklt;
cout << "corner detector klt has been chosen " << endl;
cdklt.SetMinCornerness(400);
#if type ==1
cdg = &cdklt;
#endif
break;
cd = &cdh;
cout << "corner detector harris has been chosen " << endl;
#if type == 1
cdg = &cdh;
#endif
break;
cd = &cdf;
#if type == 1
cdg = &cdf;
#endif
break;
default:
BIASERR("unknown corner detector type");
BIASABORT
break;
}
bool WantLinearRegionDetector = false;
if (WantLinearRegionDetector) {
cout << "CornerDetector not used, detecting LINEAR regions ..."<<endl;
cd = &cdl;
cd->AddDebugLevel(D_CD_WRITE_DEBUG_IM);
cd->AddDebugLevel(D_CD_FEATURES);
}
for (int i=argind; i<argc; i++){
#if type == 0
if (ImageIO::Load(argv[i], im)!=0){
#else
if (ImageIO::Load(argv[i], ucim)!=0){
#endif
BIASERR("error loading image "<<argv[i]);
return -1;
} else {
cerr << "read "<<argv[i]<<endl;
}
ImageBase tempimage;
#if type == 0
im = tempimage;
#else
ucim = tempimage;
#endif
#if type != 0
BIASERR("error converting image "<<argv[i]);
}
ImageIO::Save("fimage.mip", im);
#endif
#if type == 0
if (cd->Detect(im, p, qual)!=0) {
cerr<<"Corner detector indicated an error !"<<endl;
}
#endif
#if type == 1
if (cdg->Detect(im, p, qual)!=0) {
cerr<<"Corner detector indicated an error !"<<endl;
}
#endif
cerr << "found "<<p.size()<<" corners"<<endl;
for (unsigned int r=0; r<p.size(); r++) {
cout <<setw(5)<<r<<" : "<<p[r]<<" with quality "<<qual[r]<<endl;
}
#if type == 0
#else
#endif
Draw(rgbim, p);
ostringstream name;
name << "corners-"<<setw(4)<<setfill('0')<<i-argind<<".mip";
//ImageIO::Save(name.str(), rgbim);
ImageIO::Save(name.str(), rgbim);
}
return 0;
}