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
53 #include <cvhaartraining.h>
55 int main( int argc, char* argv[] )
58 char* nullname = "(NULL)";
59 char* vecname = NULL; /* .vec file name */
60 char* infoname = NULL; /* file name with marked up image descriptions */
61 char* imagename = NULL; /* single sample image */
62 char* bgfilename = NULL; /* background */
67 int maxintensitydev = 40;
68 double maxxangle = 1.1;
69 double maxyangle = 1.1;
70 double maxzangle = 0.5;
72 /* the samples are adjusted to this scale in the sample preview window */
79 printf( "Usage: %s\n [-info <collection_file_name>]\n"
80 " [-img <image_file_name>]\n"
81 " [-vec <vec_file_name>]\n"
82 " [-bg <background_file_name>]\n [-num <number_of_samples = %d>]\n"
83 " [-bgcolor <background_color = %d>]\n"
84 " [-inv] [-randinv] [-bgthresh <background_color_threshold = %d>]\n"
85 " [-maxidev <max_intensity_deviation = %d>]\n"
86 " [-maxxangle <max_x_rotation_angle = %f>]\n"
87 " [-maxyangle <max_y_rotation_angle = %f>]\n"
88 " [-maxzangle <max_z_rotation_angle = %f>]\n"
89 " [-show [<scale = %f>]]\n"
90 " [-w <sample_width = %d>]\n [-h <sample_height = %d>]\n",
91 argv[0], num, bgcolor, bgthreshold, maxintensitydev,
92 maxxangle, maxyangle, maxzangle, scale, width, height );
97 for( i = 1; i < argc; ++i )
99 if( !strcmp( argv[i], "-info" ) )
101 infoname = argv[++i];
103 else if( !strcmp( argv[i], "-img" ) )
105 imagename = argv[++i];
107 else if( !strcmp( argv[i], "-vec" ) )
111 else if( !strcmp( argv[i], "-bg" ) )
113 bgfilename = argv[++i];
115 else if( !strcmp( argv[i], "-num" ) )
117 num = atoi( argv[++i] );
119 else if( !strcmp( argv[i], "-bgcolor" ) )
121 bgcolor = atoi( argv[++i] );
123 else if( !strcmp( argv[i], "-bgthresh" ) )
125 bgthreshold = atoi( argv[++i] );
127 else if( !strcmp( argv[i], "-inv" ) )
131 else if( !strcmp( argv[i], "-randinv" ) )
133 invert = CV_RANDOM_INVERT;
135 else if( !strcmp( argv[i], "-maxidev" ) )
137 maxintensitydev = atoi( argv[++i] );
139 else if( !strcmp( argv[i], "-maxxangle" ) )
141 maxxangle = atof( argv[++i] );
143 else if( !strcmp( argv[i], "-maxyangle" ) )
145 maxyangle = atof( argv[++i] );
147 else if( !strcmp( argv[i], "-maxzangle" ) )
149 maxzangle = atof( argv[++i] );
151 else if( !strcmp( argv[i], "-show" ) )
154 if( i+1 < argc && strlen( argv[i+1] ) > 0 && argv[i+1][0] != '-' )
157 d = strtod( argv[i+1], 0 );
158 if( d != -HUGE_VAL && d != HUGE_VAL && d > 0 ) scale = d;
162 else if( !strcmp( argv[i], "-w" ) )
164 width = atoi( argv[++i] );
166 else if( !strcmp( argv[i], "-h" ) )
168 height = atoi( argv[++i] );
172 printf( "Info file name: %s\n", ((infoname == NULL) ? nullname : infoname ) );
173 printf( "Img file name: %s\n", ((imagename == NULL) ? nullname : imagename ) );
174 printf( "Vec file name: %s\n", ((vecname == NULL) ? nullname : vecname ) );
175 printf( "BG file name: %s\n", ((bgfilename == NULL) ? nullname : bgfilename ) );
176 printf( "Num: %d\n", num );
177 printf( "BG color: %d\n", bgcolor );
178 printf( "BG threshold: %d\n", bgthreshold );
179 printf( "Invert: %s\n", (invert == CV_RANDOM_INVERT) ? "RANDOM"
180 : ( (invert) ? "TRUE" : "FALSE" ) );
181 printf( "Max intensity deviation: %d\n", maxintensitydev );
182 printf( "Max x angle: %g\n", maxxangle );
183 printf( "Max y angle: %g\n", maxyangle );
184 printf( "Max z angle: %g\n", maxzangle );
185 printf( "Show samples: %s\n", (showsamples) ? "TRUE" : "FALSE" );
188 printf( "Scale: %g\n", scale );
190 printf( "Width: %d\n", width );
191 printf( "Height: %d\n", height );
193 /* determine action */
194 if( imagename && vecname )
196 printf( "Create training samples from single image applying distortions...\n" );
198 cvCreateTrainingSamples( vecname, imagename, bgcolor, bgthreshold, bgfilename,
199 num, invert, maxintensitydev,
200 maxxangle, maxyangle, maxzangle,
201 showsamples, width, height );
205 else if( imagename && bgfilename && infoname )
207 printf( "Create test samples from single image applying distortions...\n" );
209 cvCreateTestSamples( infoname, imagename, bgcolor, bgthreshold, bgfilename, num,
210 invert, maxintensitydev,
211 maxxangle, maxyangle, maxzangle, showsamples, width, height );
215 else if( infoname && vecname )
219 printf( "Create training samples from images collection...\n" );
221 total = cvCreateTrainingSamplesFromInfo( infoname, vecname, num, showsamples,
224 printf( "Done. Created %d samples\n", total );
228 printf( "View samples from vec file (press ESC to exit)...\n" );
230 cvShowVecSamples( vecname, width, height, scale );
236 printf( "Nothing to do\n" );