Update to 2.0.0 tree from current Fremantle build
[opencv] / apps / haartraining / cvhaartraining.h
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
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.
25 //
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.
28 //
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.
39 //
40 //M*/
41
42 /*
43  * cvhaartraining.h
44  *
45  * haar training functions
46  */
47
48 #ifndef _CVHAARTRAINING_H_
49 #define _CVHAARTRAINING_H_
50
51 /*
52  * cvCreateTrainingSamples
53  *
54  * Create training samples applying random distortions to sample image and
55  * store them in .vec file
56  *
57  * filename        - .vec file name
58  * imgfilename     - sample image file name
59  * bgcolor         - background color for sample image
60  * bgthreshold     - background color threshold. Pixels those colors are in range
61  *   [bgcolor-bgthreshold, bgcolor+bgthreshold] are considered as transparent
62  * bgfilename      - background description file name. If not NULL samples
63  *   will be put on arbitrary background
64  * count           - desired number of samples
65  * invert          - if not 0 sample foreground pixels will be inverted
66  *   if invert == CV_RANDOM_INVERT then samples will be inverted randomly
67  * maxintensitydev - desired max intensity deviation of foreground samples pixels
68  * maxxangle       - max rotation angles
69  * maxyangle
70  * maxzangle
71  * showsamples     - if not 0 samples will be shown
72  * winwidth        - desired samples width
73  * winheight       - desired samples height
74  */
75 #define CV_RANDOM_INVERT 0x7FFFFFFF
76
77 void cvCreateTrainingSamples( const char* filename,
78                               const char* imgfilename, int bgcolor, int bgthreshold,
79                               const char* bgfilename, int count,
80                               int invert = 0, int maxintensitydev = 40,
81                               double maxxangle = 1.1,
82                               double maxyangle = 1.1,
83                               double maxzangle = 0.5,
84                               int showsamples = 0,
85                               int winwidth = 24, int winheight = 24 );
86
87 void cvCreateTestSamples( const char* infoname,
88                           const char* imgfilename, int bgcolor, int bgthreshold,
89                           const char* bgfilename, int count,
90                           int invert, int maxintensitydev,
91                           double maxxangle, double maxyangle, double maxzangle,
92                           int showsamples,
93                           int winwidth, int winheight );
94
95 /*
96  * cvCreateTrainingSamplesFromInfo
97  *
98  * Create training samples from a set of marked up images and store them into .vec file
99  * infoname    - file in which marked up image descriptions are stored
100  * num         - desired number of samples
101  * showsamples - if not 0 samples will be shown
102  * winwidth    - sample width
103  * winheight   - sample height
104  * 
105  * Return number of successfully created samples
106  */
107 int cvCreateTrainingSamplesFromInfo( const char* infoname, const char* vecfilename,
108                                      int num,
109                                      int showsamples,
110                                      int winwidth, int winheight );
111
112 /*
113  * cvShowVecSamples
114  *
115  * Shows samples stored in .vec file
116  *
117  * filename
118  *   .vec file name
119  * winwidth
120  *   sample width
121  * winheight
122  *   sample height
123  * scale
124  *   the scale each sample is adjusted to
125  */
126 void cvShowVecSamples( const char* filename, int winwidth, int winheight, double scale );
127
128
129 /*
130  * cvCreateCascadeClassifier
131  *
132  * Create cascade classifier
133  * dirname          - directory name in which cascade classifier will be created.
134  *   It must exist and contain subdirectories 0, 1, 2, ... (nstages-1).
135  * vecfilename      - name of .vec file with object's images
136  * bgfilename       - name of background description file
137  * bg_vecfile       - true if bgfilename represents a vec file with discrete negatives
138  * npos             - number of positive samples used in training of each stage
139  * nneg             - number of negative samples used in training of each stage
140  * nstages          - number of stages
141  * numprecalculated - number of features being precalculated. Each precalculated feature
142  *   requires (number_of_samples*(sizeof( float ) + sizeof( short ))) bytes of memory
143  * numsplits        - number of binary splits in each weak classifier
144  *   1 - stumps, 2 and more - trees.
145  * minhitrate       - desired min hit rate of each stage
146  * maxfalsealarm    - desired max false alarm of each stage
147  * weightfraction   - weight trimming parameter
148  * mode             - 0 - BASIC = Viola
149  *                    1 - CORE  = All upright
150  *                    2 - ALL   = All features
151  * symmetric        - if not 0 vertical symmetry is assumed
152  * equalweights     - if not 0 initial weights of all samples will be equal
153  * winwidth         - sample width
154  * winheight        - sample height
155  * boosttype        - type of applied boosting algorithm
156  *   0 - Discrete AdaBoost
157  *   1 - Real AdaBoost
158  *   2 - LogitBoost
159  *   3 - Gentle AdaBoost
160  * stumperror       - type of used error if Discrete AdaBoost algorithm is applied
161  *   0 - misclassification error
162  *   1 - gini error
163  *   2 - entropy error
164  */
165 void cvCreateCascadeClassifier( const char* dirname,
166                                 const char* vecfilename,
167                                 const char* bgfilename, 
168                                 int npos, int nneg, int nstages,
169                                 int numprecalculated,
170                                 int numsplits,
171                                 float minhitrate = 0.995F, float maxfalsealarm = 0.5F,
172                                 float weightfraction = 0.95F,
173                                 int mode = 0, int symmetric = 1,
174                                 int equalweights = 1,
175                                 int winwidth = 24, int winheight = 24,
176                                 int boosttype = 3, int stumperror = 0 );
177
178 void cvCreateTreeCascadeClassifier( const char* dirname,
179                                     const char* vecfilename,
180                                     const char* bgfilename, 
181                                     int npos, int nneg, int nstages,
182                                     int numprecalculated,
183                                     int numsplits,
184                                     float minhitrate, float maxfalsealarm,
185                                     float weightfraction,
186                                     int mode, int symmetric,
187                                     int equalweights,
188                                     int winwidth, int winheight,
189                                     int boosttype, int stumperror,
190                                     int maxtreesplits, int minpos, bool bg_vecfile = false );
191
192 #endif /* _CVHAARTRAINING_H_ */