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

Example for detecting Harris Corners on images

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2004, 2004 (see file CONTACTS 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 ExampleHarrisColor.cpp
@brief Example for detecting Harris Corners on images
@relates ColorHarris
@ingroup g_examples
@author MIP
*/
#include <Base/Image/ImageConvert.hh>
#include <iostream>
#include <iomanip>
#include <Base/Image/Image.hh>
#include <FeatureDetector/ColorHarris.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/ImageUtils/ImageDraw.hh>
#include <Base/Debug/TimeMeasure.hh>
#include <getopt.h>
//give detailed time measures
//#define use_timers
using namespace BIAS;
using namespace std;
void usage(char *name)
{
cerr << endl << endl << name <<" [options] <image-filename>" << endl
<< " [-m maxnum] find maximal maxnum corners"<<endl
<< "\t\t default = 150"<<endl
<< " [-t sigma] sigma for gaussian average"<<endl
<< "\t\t default = 2.0"<<endl
<< " [-s sigma] sigma for gauss derivative (0=sobel)"<<endl
<< "\t\t default = 0"<<endl
<< " [-o out] write pointset to out"<<endl
<< endl << endl;
}
#define st_type short
int main(int argc, char *argv[])
{
char c;
unsigned int maxnum=150;
double minqual=0.00001;
double sigma1=0;
double sigma2=2.0;
// double sigma2=0;
// vector<HomgPoint2D> ps;
string file, file2, outfile("pointset.txt");
vector<float> quality;
#ifdef use_timers
int count=2;
#else
int count=200;
#endif
if (argc <2) {
usage (argv[0]);
exit(1);
}
while ((c = getopt(argc, argv, "m:t:s:o:h")) != EOF)
{
switch (c){
case 'o':
outfile=optarg;
break;
case 's':
sigma1 = atof(optarg);
break;
case 't':
sigma2 = atof(optarg);
break;
case 'h':
usage(argv[0]);
return 0;
break;
case 'm':
maxnum = atoi(optarg);
break;
default:
break;
}
}
file = argv[optind];
if (ImageIO::Load(argv[optind], image)!=0){
BIASERR("error loading file " << file);
return -1;
}
TimeMeasure time,time2;
time.start();
for (int i=0; i<count; i++){
// if(!st.IsEmpty())
// st.Release();
if (cd.CreateSTColor(image,st,sigma1,sigma2)!=0){
BIASERR("error creating st");
return -1;
}
#ifdef use_timers
time2.start();
#endif
cd.HarrisValue(st,res);
#ifdef use_timers
time2.stop();
cout <<"\nHarrisValue took:\n";
time2.print();
time2.Reset();
#endif
}
time.stop();
cout <<"\n"<<count<<" st harris took:\n";
time.print();
//ImageIO::Save("res.mip",res);
ImageIO::Save("res.mip",res);
//ImageIO::Save("st.mip",st2);
ImageIO::Save("st.mip",st2);
// NonMax<int> nm;
// Image<int> res2;
// res2=res;
// nm.Filter(res,res2);
// ImageIO::Save("res2.mip",res2);
return 0;
}