1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
45 * Create test/training samples
56 #include "cvhaartraining.h"
58 int main( int argc, char* argv[] )
61 char* nullname = (char*)"(NULL)";
62 char* vecname = NULL; /* .vec file name */
63 char* infoname = NULL; /* file name with marked up image descriptions */
64 char* imagename = NULL; /* single sample image */
65 char* bgfilename = NULL; /* background */
70 int maxintensitydev = 40;
71 double maxxangle = 1.1;
72 double maxyangle = 1.1;
73 double maxzangle = 0.5;
75 /* the samples are adjusted to this scale in the sample preview window */
80 srand((unsigned int)time(0));
84 printf( "Usage: %s\n [-info <collection_file_name>]\n"
85 " [-img <image_file_name>]\n"
86 " [-vec <vec_file_name>]\n"
87 " [-bg <background_file_name>]\n [-num <number_of_samples = %d>]\n"
88 " [-bgcolor <background_color = %d>]\n"
89 " [-inv] [-randinv] [-bgthresh <background_color_threshold = %d>]\n"
90 " [-maxidev <max_intensity_deviation = %d>]\n"
91 " [-maxxangle <max_x_rotation_angle = %f>]\n"
92 " [-maxyangle <max_y_rotation_angle = %f>]\n"
93 " [-maxzangle <max_z_rotation_angle = %f>]\n"
94 " [-show [<scale = %f>]]\n"
95 " [-w <sample_width = %d>]\n [-h <sample_height = %d>]\n",
96 argv[0], num, bgcolor, bgthreshold, maxintensitydev,
97 maxxangle, maxyangle, maxzangle, scale, width, height );
102 for( i = 1; i < argc; ++i )
104 if( !strcmp( argv[i], "-info" ) )
106 infoname = argv[++i];
108 else if( !strcmp( argv[i], "-img" ) )
110 imagename = argv[++i];
112 else if( !strcmp( argv[i], "-vec" ) )
116 else if( !strcmp( argv[i], "-bg" ) )
118 bgfilename = argv[++i];
120 else if( !strcmp( argv[i], "-num" ) )
122 num = atoi( argv[++i] );
124 else if( !strcmp( argv[i], "-bgcolor" ) )
126 bgcolor = atoi( argv[++i] );
128 else if( !strcmp( argv[i], "-bgthresh" ) )
130 bgthreshold = atoi( argv[++i] );
132 else if( !strcmp( argv[i], "-inv" ) )
136 else if( !strcmp( argv[i], "-randinv" ) )
138 invert = CV_RANDOM_INVERT;
140 else if( !strcmp( argv[i], "-maxidev" ) )
142 maxintensitydev = atoi( argv[++i] );
144 else if( !strcmp( argv[i], "-maxxangle" ) )
146 maxxangle = atof( argv[++i] );
148 else if( !strcmp( argv[i], "-maxyangle" ) )
150 maxyangle = atof( argv[++i] );
152 else if( !strcmp( argv[i], "-maxzangle" ) )
154 maxzangle = atof( argv[++i] );
156 else if( !strcmp( argv[i], "-show" ) )
159 if( i+1 < argc && strlen( argv[i+1] ) > 0 && argv[i+1][0] != '-' )
162 d = strtod( argv[i+1], 0 );
163 if( d != -HUGE_VAL && d != HUGE_VAL && d > 0 ) scale = d;
167 else if( !strcmp( argv[i], "-w" ) )
169 width = atoi( argv[++i] );
171 else if( !strcmp( argv[i], "-h" ) )
173 height = atoi( argv[++i] );
177 printf( "Info file name: %s\n", ((infoname == NULL) ? nullname : infoname ) );
178 printf( "Img file name: %s\n", ((imagename == NULL) ? nullname : imagename ) );
179 printf( "Vec file name: %s\n", ((vecname == NULL) ? nullname : vecname ) );
180 printf( "BG file name: %s\n", ((bgfilename == NULL) ? nullname : bgfilename ) );
181 printf( "Num: %d\n", num );
182 printf( "BG color: %d\n", bgcolor );
183 printf( "BG threshold: %d\n", bgthreshold );
184 printf( "Invert: %s\n", (invert == CV_RANDOM_INVERT) ? "RANDOM"
185 : ( (invert) ? "TRUE" : "FALSE" ) );
186 printf( "Max intensity deviation: %d\n", maxintensitydev );
187 printf( "Max x angle: %g\n", maxxangle );
188 printf( "Max y angle: %g\n", maxyangle );
189 printf( "Max z angle: %g\n", maxzangle );
190 printf( "Show samples: %s\n", (showsamples) ? "TRUE" : "FALSE" );
193 printf( "Scale: %g\n", scale );
195 printf( "Width: %d\n", width );
196 printf( "Height: %d\n", height );
198 /* determine action */
199 if( imagename && vecname )
201 printf( "Create training samples from single image applying distortions...\n" );
203 cvCreateTrainingSamples( vecname, imagename, bgcolor, bgthreshold, bgfilename,
204 num, invert, maxintensitydev,
205 maxxangle, maxyangle, maxzangle,
206 showsamples, width, height );
210 else if( imagename && bgfilename && infoname )
212 printf( "Create test samples from single image applying distortions...\n" );
214 cvCreateTestSamples( infoname, imagename, bgcolor, bgthreshold, bgfilename, num,
215 invert, maxintensitydev,
216 maxxangle, maxyangle, maxzangle, showsamples, width, height );
220 else if( infoname && vecname )
224 printf( "Create training samples from images collection...\n" );
226 total = cvCreateTrainingSamplesFromInfo( infoname, vecname, num, showsamples,
229 printf( "Done. Created %d samples\n", total );
233 printf( "View samples from vec file (press ESC to exit)...\n" );
235 cvShowVecSamples( vecname, width, height, scale );
241 printf( "Nothing to do\n" );