Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <string.h>
00026 #include <stdio.h>
00027
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
00086 vector<Point> foundPointsList;
00087 vector<double> confidencesList;
00088
00089
00090
00091 if(!FastMatchTemplate(source,
00092 target,
00093 &foundPointsList,
00094 &confidencesList))
00095 {
00096 printf("\nERROR: Fast match template failed.\n");
00097 return 3;
00098 }
00099
00100
00101
00102
00103
00104 Mat colorImage;
00105
00106
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
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
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 }