MatchPoint.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Zoran Mesec   *
00003  *   zoran.mesec@gmail.com   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 //#define USE_OPENCV
00021 //#define USE_QT
00022 #define USE_VIGRA
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include <stdio.h>
00029 #include <iostream>
00030 #include <stdlib.h>
00031 #include <math.h>
00032 #include <ctime>
00033 #include <algorithm>
00034 
00035 #include <string>
00036 #include "APImage.h"
00037 #include "HessianDetector.h"
00038 #include "Descriptor.h"
00039 
00040 #include "getopt.h"
00041 
00042 #include <limits>
00043 
00044 #ifdef WIN32
00045  #include <getopt.h>
00046 #else
00047  #include <unistd.h>
00048 #endif
00049 
00050 
00051 using namespace std;
00052 
00053 void usage()
00054 {
00055     cout << "MatchPoint: run feature detection and extraction" << endl
00056          << endl
00057          << "Usage:  MatchPoint [options] image1.jpg output.key" << endl
00058          << "Options:" << endl
00059 
00060     /*    // << "  -x              generate xml suitable for Autopano-SIFT feature matcher" << endl
00061          << "  -o file          generate XML file with interest points and descriptors(image1.jpg.xml, image2.jpg.xml)" << endl
00062          << "  -n num          extract num interest points an descriptors" << endl*/
00063      << "  -v              verbose output" << endl
00064      << "  -t              generate keypoint file for matlab test suite(file name is generated using formula: image1.jpg.key)" << endl
00065          //<< "                  TODO: replace with threshold, default 1000" << endl
00066          << "Arguments:" << endl
00067          << "  image1.jpg      Path to image to be analyzed." << endl
00068          << "  output.key      Output keypoint file.." << endl
00069          << endl;
00070 }
00071 
00072 
00073 int main(int argc, char *argv[])
00074 {
00075 
00076 
00077 
00078     const char * optstring = "hvt";
00079     char c;
00080     clock_t start,finish;
00081     double time;
00082 
00083     bool verbose = false;
00084     bool testFileOutput = false;
00085     string input1;
00086     string output;
00087 
00088     // parse arguments
00089     while ((c = getopt (argc, argv, optstring)) != -1)
00090     {
00091         switch(c) {
00092             case 'v':
00093                 verbose = true;
00094                 break;
00095             case 't':
00096                 testFileOutput=true;
00097                 break;
00098             /*case 'o':
00099                 output = optarg;
00100             break;
00101         case 'n':
00102             nrPoints = atoi(optarg);
00103             break;*/
00104             case 'h':
00105                 usage();
00106                 //return 0;
00107                 break;
00108             default:
00109                 usage();
00110                 return 0;
00111         }
00112         //optind++;
00113     }
00114 
00115     if (optind+2 !=  argc) {
00116         usage();
00117        return 1;
00118     }
00119 
00120     input1=argv[optind];
00121     output=argv[optind+1];
00122     if (verbose) cerr << "Input image: " <<input1 << "; Output key file: "<<output<<endl;
00123 
00124     APImage im1(input1);
00125     if(!im1.open()) {
00126         cerr<< "Error! Image can not be opened"<<"\n";
00127         return 0;
00128     }
00129 
00130     //need to integrate the image before the detection process(only if using box filter approximation)
00131     im1.integrate();
00132 
00133     start = clock();
00134 
00135     HessianDetector hd1(&im1,0, HD_BOX_FILTERS,1);
00136     if(!hd1.detect()) {
00137         cerr << "Detection of points failed!";
00138         return 1;
00139     }
00140 
00141     finish = clock();
00142 
00143     time = (double(finish)-double(start))/CLOCKS_PER_SEC;
00144     cout << "Measured time:"<<time<<"\n";
00145 
00146     vector<vector<int> >* interestPoints1=hd1.getPoints();
00147 
00148     Descriptor d1(&im1,&hd1);
00149     d1.setPoints(interestPoints1);
00150     //d.orientate();
00151     d1.createDescriptors();
00152 
00153     if(testFileOutput) {
00154 //        string testOutputPath = input1.append(".key");
00155         if (verbose) cerr << "Generating output file for matlab test suite: " << output << endl;
00156         d1.printDescriptors(output);   //for matlab test suite
00157     } else {
00158         d1.generateAutopanoXML(output);
00159     }
00160 
00161     return EXIT_SUCCESS;
00162 }

Generated on Mon Sep 9 01:25:42 2013 for Hugintrunk by  doxygen 1.3.9.1