main.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *            main.cpp
00003  *
00004  *
00005  *  Copyright  2010  Tristen Georgiou
00006  *  tristen_georgiou@hotmail.com
00007  ****************************************************************************/
00008 
00009 /*
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024 
00025 #include <string.h>
00026 #include <stdio.h>
00027 //#include <time.h>
00028 
00029 #include <opencv/cv.h>
00030 #include <opencv/highgui.h>
00031 #include "fast_match_template/FastMatchTemplate.h"
00032 
00033 using namespace cv;
00034 
00035 int searchForParameter(const char* param,
00036                        int         numArgs,
00037                        char**      argList);
00038 
00039 void printOptions();
00040 
00041 int main(int argc, char** argv)
00042 {
00043     if( argc != 7 )
00044     {
00045         printf( "\nERROR: Required arguments missing.\n" );
00046         printOptions();
00047         return 1;
00048     }
00049 
00050     int sourceParam = searchForParameter("-s", argc, argv);
00051     if(sourceParam == -1)
00052     {
00053         printf( "\nERROR: Source argument missing.\n" );
00054         return 1;
00055     }
00056 
00057     int targetParam = searchForParameter("-t", argc, argv);
00058     if(targetParam == -1)
00059     {
00060         printf( "\nERROR: Target argument missing.\n" );
00061         return 1;
00062     }
00063 
00064     int nameParam = searchForParameter("-n", argc, argv);
00065     if(nameParam == -1)
00066       {
00067         printf( "\nERROR: Name argument missing.\n" );
00068         return 1;
00069     }
00070 
00071     Mat source = imread(argv[++sourceParam]);
00072     if(!source.data)
00073     {
00074         printf("\nERROR: Could not load image %s.\n", argv[sourceParam]);
00075         return 2;
00076     }
00077 
00078     Mat target = imread(argv[++targetParam]);
00079     if(!target.data)
00080     {
00081         printf("\nERROR: Could not load image %s.\n", argv[targetParam]);
00082         return 2;
00083     }
00084 
00085     // perform the match
00086     vector<Point> foundPointsList;
00087     vector<double> confidencesList;
00088 
00089     // start the timer
00090     //clock_t start = clock();
00091     if(!FastMatchTemplate(source,
00092                           target,
00093                           &foundPointsList,
00094                           &confidencesList))
00095     {
00096         printf("\nERROR: Fast match template failed.\n");
00097         return 3;
00098     }
00099     //clock_t elapsed = clock() - start;
00100     //long int timeMs = ((float)elapsed) / ((float)CLOCKS_PER_SEC) * 1000.0f;
00101     //printf("\nINFO: FastMatchTemplate() function took %ld ms.\n", timeMs);
00102 
00103     // create a color image to draw on
00104     Mat colorImage;
00105 
00106     // if the original is a grayscale image, convert it to color
00107     if(source.channels() == 1)
00108     {
00109         cvtColor(source, colorImage, CV_GRAY2RGB);
00110     }
00111     else
00112     {
00113         colorImage = source.clone();
00114     }
00115 
00116     DrawFoundTargets(&colorImage,
00117                      target.size(),
00118                      foundPointsList,
00119                      confidencesList);
00120 
00121     // wait for both windows to be closed before releasing images
00122     imshow("Results", colorImage);
00123     waitKey(0);
00124     imwrite(string(argv[++nameParam]) + ".png", colorImage);
00125     return 0;
00126 }
00127 
00128 int searchForParameter(const char* param,
00129                        int         numArgs,
00130                        char**      argList)
00131 {
00132     for(int currArg = 0; currArg < numArgs; currArg++)
00133     {
00134         if(strcmp( param, argList[currArg] ) == 0)
00135         {
00136             return currArg;
00137         }
00138     }
00139 
00140     // argument not found
00141     return -1;
00142 }
00143 
00144 void printOptions()
00145 {
00146     printf("\nFAST MATCH TEMPLATE EXAMPLE PROGRAM\n");
00147     printf("-----------------------------------\n");
00148     printf("\nProgram arguments:\n\n" );
00149     printf("     -s source image name (image to be searched)\n\n");
00150     printf("     -t target image name (image we are trying to find)\n\n");
00151     printf("     -n result image name (name of result image we are saving)\n\n");
00152     printf("Example: FastMatchTemplate -s source.bmp -t target.bmp -n result.png \n\n");
00153 }


fast_match_template
Author(s): Tristen Georgiou, Dejan Pangercic (for ROS and modifications)
autogenerated on Mon Oct 6 2014 08:23:34