OpenCV 4.5.3(日本語機械翻訳)
onlineBoosting.hpp
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 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2013, OpenCV Foundation, 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 the copyright holders 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 #ifndef __OPENCV_ONLINEBOOSTING_HPP__
43 #define __OPENCV_ONLINEBOOSTING_HPP__
44
45 #include "opencv2/core.hpp"
46
47 namespace cv {
48 namespace detail {
49 inline namespace tracking {
50
53
54 inline namespace online_boosting {
55
56 //TODO based on the original implementation
57 //http://vision.ucsd.edu/~bbabenko/project_miltrack.shtml
58
59 class BaseClassifier;
60 class WeakClassifierHaarFeature;
61 class EstimatedGaussDistribution;
62 class ClassifierThreshold;
63 class Detector;
64
66{
67 public:
68
69 StrongClassifierDirectSelection( int numBaseClf, int numWeakClf, Size patchSz, const Rect& sampleROI, bool useFeatureEx = false, int iterationInit =
70 0 );
72
73 void initBaseClassifier();
74
75 bool update( const Mat& image, int target, float importance = 1.0 );
76 float eval( const Mat& response );
77 std::vector<int> getSelectedWeakClassifier();
78 float classifySmooth( const std::vector<Mat>& images, const Rect& sampleROI, int& idx );
79 int getNumBaseClassifier();
80 Size getPatchSize() const;
81 Rect getROI() const;
82 bool getUseFeatureExchange() const;
83 int getReplacedClassifier() const;
84
85 void replaceWeakClassifier( int idx );
86 int getSwappedClassifier() const;
87 private:
88
89 //StrongClassifier
90 int numBaseClassifier;
91 int numAllWeakClassifier;
92 int numWeakClassifier;
93 int iterInit;
94 BaseClassifier** baseClassifier;
95 std::vector<float> alpha;
96 cv::Size patchSize;
97
98 bool useFeatureExchange;
99
100 //StrongClassifierDirectSelection
101 std::vector<bool> m_errorMask;
102 std::vector<float> m_errors;
103 std::vector<float> m_sumErrors;
104
105 Detector* detector;
106 Rect ROI;
107
108 int replacedClassifier;
109 int swappedClassifier;
110};
111
113{
114 public:
115
116 BaseClassifier( int numWeakClassifier, int iterationInit );
117 BaseClassifier( int numWeakClassifier, int iterationInit, WeakClassifierHaarFeature** weakCls );
118
119 WeakClassifierHaarFeature** getReferenceWeakClassifier()
120 {
121 return weakClassifier;
122 }
123 ;
124 void trainClassifier( const Mat& image, int target, float importance, std::vector<bool>& errorMask );
125 int selectBestClassifier( std::vector<bool>& errorMask, float importance, std::vector<float> & errors );
126 int computeReplaceWeakestClassifier( const std::vector<float> & errors );
127 void replaceClassifierStatistic( int sourceIndex, int targetIndex );
128 int getIdxOfNewWeakClassifier()
129 {
130 return m_idxOfNewWeakClassifier;
131 }
132 ;
133 int eval( const Mat& image );
134 virtual ~BaseClassifier();
135 float getError( int curWeakClassifier );
136 void getErrors( float* errors );
137 int getSelectedClassifier() const;
138 void replaceWeakClassifier( int index );
139
140 protected:
141
142 void generateRandomClassifier();
143 WeakClassifierHaarFeature** weakClassifier;
144 bool m_referenceWeakClassifier;
145 int m_numWeakClassifier;
146 int m_selectedClassifier;
147 int m_idxOfNewWeakClassifier;
148 std::vector<float> m_wCorrect;
149 std::vector<float> m_wWrong;
150 int m_iterationInit;
151
152};
153
155{
156 public:
157
159 EstimatedGaussDistribution( float P_mean, float R_mean, float P_sigma, float R_sigma );
161 void update( float value ); //, float timeConstant = -1.0);
162 float getMean();
163 float getSigma();
164 void setValues( float mean, float sigma );
165
166 private:
167
168 float m_mean;
169 float m_sigma;
170 float m_P_mean;
171 float m_P_sigma;
172 float m_R_mean;
173 float m_R_sigma;
174};
175
177{
178
179 public:
180
183
184 bool update( float value, int target );
185 int eval( float value );
186
187 private:
188
189 float sigma;
190 float mean;
191 ClassifierThreshold* m_classifier;
192
193 void getInitialDistribution( EstimatedGaussDistribution *distribution );
194 void generateRandomClassifier( EstimatedGaussDistribution* m_posSamples, EstimatedGaussDistribution* m_negSamples );
195
196};
197
198 class Detector
199{
200 public:
201
203 virtual
204 ~Detector( void );
205
206 void
207 classifySmooth( const std::vector<Mat>& image, float minMargin = 0 );
208
209 int
210 getNumDetections();
211 float
212 getConfidence( int patchIdx );
213 float
214 getConfidenceOfDetection( int detectionIdx );
215
216 float getConfidenceOfBestDetection()
217 {
218 return m_maxConfidence;
219 }
220 ;
221 int
222 getPatchIdxOfBestDetection();
223
224 int
225 getPatchIdxOfDetection( int detectionIdx );
226
227 const std::vector<int> &
228 getIdxDetections() const
229 {
230 return m_idxDetections;
231 }
232 ;
233 const std::vector<float> &
234 getConfidences() const
235 {
236 return m_confidences;
237 }
238 ;
239
240 const cv::Mat &
241 getConfImageDisplay() const
242 {
243 return m_confImageDisplay;
244 }
245
246 private:
247
248 void
249 prepareConfidencesMemory( int numPatches );
250 void
251 prepareDetectionsMemory( int numDetections );
252
254 std::vector<float> m_confidences;
255 int m_sizeConfidences;
256 int m_numDetections;
257 std::vector<int> m_idxDetections;
258 int m_sizeDetections;
259 int m_idxBestDetection;
260 float m_maxConfidence;
261 cv::Mat_<float> m_confMatrix;
262 cv::Mat_<float> m_confMatrixSmooth;
263 cv::Mat_<unsigned char> m_confImageDisplay;
264};
265
267{
268 public:
269
271 virtual ~ClassifierThreshold();
272
273 void update( float value, int target );
274 int eval( float value );
275
276 void* getDistribution( int target );
277
278 private:
279
280 EstimatedGaussDistribution* m_posSamples;
281 EstimatedGaussDistribution* m_negSamples;
282
283 float m_threshold;
284 int m_parity;
285};
286
287} // namespace
288
290
291}}} // namespace
292
293 #endif
Template matrix class derived from Mat
Definition: mat.hpp:2199
n-dimensional dense array class
Definition: mat.hpp:802
Template class for 2D rectangles
Definition: core/types.hpp:421
Template class for specifying the size of an image or rectangle.
Definition: core/types.hpp:316
Definition: onlineBoosting.hpp:113
Definition: onlineBoosting.hpp:199
Definition: onlineBoosting.hpp:155
Definition: onlineBoosting.hpp:66
Definition: onlineBoosting.hpp:177
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75