Merge pull request #2887 from ilya-lavrenov:ipp_morph_fix
[platform/upstream/opencv.git] / apps / sft / include / sft / config.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) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42
43 #ifndef __SFT_CONFIG_HPP__
44 #define __SFT_CONFIG_HPP__
45
46 #include <sft/common.hpp>
47
48 #include <ostream>
49
50 namespace sft {
51
52 struct Config
53 {
54     Config();
55
56     void write(cv::FileStorage& fs) const;
57
58     void read(const cv::FileNode& node);
59
60     // Scaled and shrunk model size.
61     cv::Size model(ivector::const_iterator it) const
62     {
63         float octave = powf(2.f, (float)(*it));
64         return cv::Size( cvRound(modelWinSize.width  * octave) / shrinkage,
65                          cvRound(modelWinSize.height * octave) / shrinkage );
66     }
67
68     // Scaled but, not shrunk bounding box for object in sample image.
69     cv::Rect bbox(ivector::const_iterator it) const
70     {
71         float octave = powf(2.f, (float)(*it));
72         return cv::Rect( cvRound(offset.x * octave), cvRound(offset.y * octave),
73             cvRound(modelWinSize.width  * octave), cvRound(modelWinSize.height * octave));
74     }
75
76     string resPath(ivector::const_iterator it) const
77     {
78         return cv::format("%s%d.xml",cascadeName.c_str(), *it);
79     }
80
81     // Paths to a rescaled data
82     string trainPath;
83     string testPath;
84
85     // Original model size.
86     cv::Size modelWinSize;
87
88     // example offset into positive image
89     cv::Point2i offset;
90
91     // List of octaves for which have to be trained cascades (a list of powers of two)
92     ivector octaves;
93
94     // Maximum number of positives that should be used during training
95     int positives;
96
97     // Initial number of negatives used during training.
98     int negatives;
99
100     // Number of weak negatives to add each bootstrapping step.
101     int btpNegatives;
102
103     // Inverse of scale for feature resizing
104     int shrinkage;
105
106     // Depth on weak classifier's decision tree
107     int treeDepth;
108
109     // Weak classifiers number in resulted cascade
110     int weaks;
111
112     // Feature random pool size
113     int poolSize;
114
115     // file name to store cascade
116     string cascadeName;
117
118     // path to resulting cascade
119     string outXmlPath;
120
121     // seed for random generation
122     int seed;
123
124     // channel feature type
125     string featureType;
126
127     // // bounding rectangle for actual example into example window
128     // cv::Rect exampleWindow;
129 };
130
131 // required for cv::FileStorage serialization
132 void write(cv::FileStorage& fs, const string&, const Config& x);
133 void read(const cv::FileNode& node, Config& x, const Config& default_value);
134 std::ostream& operator<<(std::ostream& out, const Config& m);
135
136 }
137
138 #endif