Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Thu Jun 29 11:00:41 2017 +0000
Revision:
166:3a9487d57a5c
This is Opencv 3.1 project on GR-PEACH board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 166:3a9487d57a5c 1 /*M///////////////////////////////////////////////////////////////////////////////////////
thedo 166:3a9487d57a5c 2 //
thedo 166:3a9487d57a5c 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
thedo 166:3a9487d57a5c 4 //
thedo 166:3a9487d57a5c 5 // By downloading, copying, installing or using the software you agree to this license.
thedo 166:3a9487d57a5c 6 // If you do not agree to this license, do not download, install,
thedo 166:3a9487d57a5c 7 // copy or use the software.
thedo 166:3a9487d57a5c 8 //
thedo 166:3a9487d57a5c 9 //
thedo 166:3a9487d57a5c 10 // License Agreement
thedo 166:3a9487d57a5c 11 // For Open Source Computer Vision Library
thedo 166:3a9487d57a5c 12 //
thedo 166:3a9487d57a5c 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
thedo 166:3a9487d57a5c 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
thedo 166:3a9487d57a5c 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
thedo 166:3a9487d57a5c 16 // Third party copyrights are property of their respective owners.
thedo 166:3a9487d57a5c 17 //
thedo 166:3a9487d57a5c 18 // Redistribution and use in source and binary forms, with or without modification,
thedo 166:3a9487d57a5c 19 // are permitted provided that the following conditions are met:
thedo 166:3a9487d57a5c 20 //
thedo 166:3a9487d57a5c 21 // * Redistribution's of source code must retain the above copyright notice,
thedo 166:3a9487d57a5c 22 // this list of conditions and the following disclaimer.
thedo 166:3a9487d57a5c 23 //
thedo 166:3a9487d57a5c 24 // * Redistribution's in binary form must reproduce the above copyright notice,
thedo 166:3a9487d57a5c 25 // this list of conditions and the following disclaimer in the documentation
thedo 166:3a9487d57a5c 26 // and/or other materials provided with the distribution.
thedo 166:3a9487d57a5c 27 //
thedo 166:3a9487d57a5c 28 // * The name of the copyright holders may not be used to endorse or promote products
thedo 166:3a9487d57a5c 29 // derived from this software without specific prior written permission.
thedo 166:3a9487d57a5c 30 //
thedo 166:3a9487d57a5c 31 // This software is provided by the copyright holders and contributors "as is" and
thedo 166:3a9487d57a5c 32 // any express or implied warranties, including, but not limited to, the implied
thedo 166:3a9487d57a5c 33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
thedo 166:3a9487d57a5c 34 // In no event shall the Intel Corporation or contributors be liable for any direct,
thedo 166:3a9487d57a5c 35 // indirect, incidental, special, exemplary, or consequential damages
thedo 166:3a9487d57a5c 36 // (including, but not limited to, procurement of substitute goods or services;
thedo 166:3a9487d57a5c 37 // loss of use, data, or profits; or business interruption) however caused
thedo 166:3a9487d57a5c 38 // and on any theory of liability, whether in contract, strict liability,
thedo 166:3a9487d57a5c 39 // or tort (including negligence or otherwise) arising in any way out of
thedo 166:3a9487d57a5c 40 // the use of this software, even if advised of the possibility of such damage.
thedo 166:3a9487d57a5c 41 //
thedo 166:3a9487d57a5c 42 //M*/
thedo 166:3a9487d57a5c 43
thedo 166:3a9487d57a5c 44 #ifndef __OPENCV_OBJDETECT_HPP__
thedo 166:3a9487d57a5c 45 #define __OPENCV_OBJDETECT_HPP__
thedo 166:3a9487d57a5c 46
thedo 166:3a9487d57a5c 47 #include "opencv2/core.hpp"
thedo 166:3a9487d57a5c 48
thedo 166:3a9487d57a5c 49 /**
thedo 166:3a9487d57a5c 50 @defgroup objdetect Object Detection
thedo 166:3a9487d57a5c 51
thedo 166:3a9487d57a5c 52 Haar Feature-based Cascade Classifier for Object Detection
thedo 166:3a9487d57a5c 53 ----------------------------------------------------------
thedo 166:3a9487d57a5c 54
thedo 166:3a9487d57a5c 55 The object detector described below has been initially proposed by Paul Viola @cite Viola01 and
thedo 166:3a9487d57a5c 56 improved by Rainer Lienhart @cite Lienhart02 .
thedo 166:3a9487d57a5c 57
thedo 166:3a9487d57a5c 58 First, a classifier (namely a *cascade of boosted classifiers working with haar-like features*) is
thedo 166:3a9487d57a5c 59 trained with a few hundred sample views of a particular object (i.e., a face or a car), called
thedo 166:3a9487d57a5c 60 positive examples, that are scaled to the same size (say, 20x20), and negative examples - arbitrary
thedo 166:3a9487d57a5c 61 images of the same size.
thedo 166:3a9487d57a5c 62
thedo 166:3a9487d57a5c 63 After a classifier is trained, it can be applied to a region of interest (of the same size as used
thedo 166:3a9487d57a5c 64 during the training) in an input image. The classifier outputs a "1" if the region is likely to show
thedo 166:3a9487d57a5c 65 the object (i.e., face/car), and "0" otherwise. To search for the object in the whole image one can
thedo 166:3a9487d57a5c 66 move the search window across the image and check every location using the classifier. The
thedo 166:3a9487d57a5c 67 classifier is designed so that it can be easily "resized" in order to be able to find the objects of
thedo 166:3a9487d57a5c 68 interest at different sizes, which is more efficient than resizing the image itself. So, to find an
thedo 166:3a9487d57a5c 69 object of an unknown size in the image the scan procedure should be done several times at different
thedo 166:3a9487d57a5c 70 scales.
thedo 166:3a9487d57a5c 71
thedo 166:3a9487d57a5c 72 The word "cascade" in the classifier name means that the resultant classifier consists of several
thedo 166:3a9487d57a5c 73 simpler classifiers (*stages*) that are applied subsequently to a region of interest until at some
thedo 166:3a9487d57a5c 74 stage the candidate is rejected or all the stages are passed. The word "boosted" means that the
thedo 166:3a9487d57a5c 75 classifiers at every stage of the cascade are complex themselves and they are built out of basic
thedo 166:3a9487d57a5c 76 classifiers using one of four different boosting techniques (weighted voting). Currently Discrete
thedo 166:3a9487d57a5c 77 Adaboost, Real Adaboost, Gentle Adaboost and Logitboost are supported. The basic classifiers are
thedo 166:3a9487d57a5c 78 decision-tree classifiers with at least 2 leaves. Haar-like features are the input to the basic
thedo 166:3a9487d57a5c 79 classifiers, and are calculated as described below. The current algorithm uses the following
thedo 166:3a9487d57a5c 80 Haar-like features:
thedo 166:3a9487d57a5c 81
thedo 166:3a9487d57a5c 82 ![image](pics/haarfeatures.png)
thedo 166:3a9487d57a5c 83
thedo 166:3a9487d57a5c 84 The feature used in a particular classifier is specified by its shape (1a, 2b etc.), position within
thedo 166:3a9487d57a5c 85 the region of interest and the scale (this scale is not the same as the scale used at the detection
thedo 166:3a9487d57a5c 86 stage, though these two scales are multiplied). For example, in the case of the third line feature
thedo 166:3a9487d57a5c 87 (2c) the response is calculated as the difference between the sum of image pixels under the
thedo 166:3a9487d57a5c 88 rectangle covering the whole feature (including the two white stripes and the black stripe in the
thedo 166:3a9487d57a5c 89 middle) and the sum of the image pixels under the black stripe multiplied by 3 in order to
thedo 166:3a9487d57a5c 90 compensate for the differences in the size of areas. The sums of pixel values over a rectangular
thedo 166:3a9487d57a5c 91 regions are calculated rapidly using integral images (see below and the integral description).
thedo 166:3a9487d57a5c 92
thedo 166:3a9487d57a5c 93 To see the object detector at work, have a look at the facedetect demo:
thedo 166:3a9487d57a5c 94 <https://github.com/Itseez/opencv/tree/master/samples/cpp/dbt_face_detection.cpp>
thedo 166:3a9487d57a5c 95
thedo 166:3a9487d57a5c 96 The following reference is for the detection part only. There is a separate application called
thedo 166:3a9487d57a5c 97 opencv_traincascade that can train a cascade of boosted classifiers from a set of samples.
thedo 166:3a9487d57a5c 98
thedo 166:3a9487d57a5c 99 @note In the new C++ interface it is also possible to use LBP (local binary pattern) features in
thedo 166:3a9487d57a5c 100 addition to Haar-like features. .. [Viola01] Paul Viola and Michael J. Jones. Rapid Object Detection
thedo 166:3a9487d57a5c 101 using a Boosted Cascade of Simple Features. IEEE CVPR, 2001. The paper is available online at
thedo 166:3a9487d57a5c 102 <http://research.microsoft.com/en-us/um/people/viola/Pubs/Detect/violaJones_CVPR2001.pdf>
thedo 166:3a9487d57a5c 103
thedo 166:3a9487d57a5c 104 @{
thedo 166:3a9487d57a5c 105 @defgroup objdetect_c C API
thedo 166:3a9487d57a5c 106 @}
thedo 166:3a9487d57a5c 107 */
thedo 166:3a9487d57a5c 108
thedo 166:3a9487d57a5c 109 typedef struct CvHaarClassifierCascade CvHaarClassifierCascade;
thedo 166:3a9487d57a5c 110
thedo 166:3a9487d57a5c 111 namespace cv
thedo 166:3a9487d57a5c 112 {
thedo 166:3a9487d57a5c 113
thedo 166:3a9487d57a5c 114 //! @addtogroup objdetect
thedo 166:3a9487d57a5c 115 //! @{
thedo 166:3a9487d57a5c 116
thedo 166:3a9487d57a5c 117 ///////////////////////////// Object Detection ////////////////////////////
thedo 166:3a9487d57a5c 118
thedo 166:3a9487d57a5c 119 //! class for grouping object candidates, detected by Cascade Classifier, HOG etc.
thedo 166:3a9487d57a5c 120 //! instance of the class is to be passed to cv::partition (see cxoperations.hpp)
thedo 166:3a9487d57a5c 121 class CV_EXPORTS SimilarRects
thedo 166:3a9487d57a5c 122 {
thedo 166:3a9487d57a5c 123 public:
thedo 166:3a9487d57a5c 124 SimilarRects(double _eps) : eps(_eps) {}
thedo 166:3a9487d57a5c 125 inline bool operator()(const Rect& r1, const Rect& r2) const
thedo 166:3a9487d57a5c 126 {
thedo 166:3a9487d57a5c 127 double delta = eps*(std::min(r1.width, r2.width) + std::min(r1.height, r2.height))*0.5;
thedo 166:3a9487d57a5c 128 return std::abs(r1.x - r2.x) <= delta &&
thedo 166:3a9487d57a5c 129 std::abs(r1.y - r2.y) <= delta &&
thedo 166:3a9487d57a5c 130 std::abs(r1.x + r1.width - r2.x - r2.width) <= delta &&
thedo 166:3a9487d57a5c 131 std::abs(r1.y + r1.height - r2.y - r2.height) <= delta;
thedo 166:3a9487d57a5c 132 }
thedo 166:3a9487d57a5c 133 double eps;
thedo 166:3a9487d57a5c 134 };
thedo 166:3a9487d57a5c 135
thedo 166:3a9487d57a5c 136 /** @brief Groups the object candidate rectangles.
thedo 166:3a9487d57a5c 137
thedo 166:3a9487d57a5c 138 @param rectList Input/output vector of rectangles. Output vector includes retained and grouped
thedo 166:3a9487d57a5c 139 rectangles. (The Python list is not modified in place.)
thedo 166:3a9487d57a5c 140 @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a
thedo 166:3a9487d57a5c 141 group of rectangles to retain it.
thedo 166:3a9487d57a5c 142 @param eps Relative difference between sides of the rectangles to merge them into a group.
thedo 166:3a9487d57a5c 143
thedo 166:3a9487d57a5c 144 The function is a wrapper for the generic function partition . It clusters all the input rectangles
thedo 166:3a9487d57a5c 145 using the rectangle equivalence criteria that combines rectangles with similar sizes and similar
thedo 166:3a9487d57a5c 146 locations. The similarity is defined by eps. When eps=0 , no clustering is done at all. If
thedo 166:3a9487d57a5c 147 \f$\texttt{eps}\rightarrow +\inf\f$ , all the rectangles are put in one cluster. Then, the small
thedo 166:3a9487d57a5c 148 clusters containing less than or equal to groupThreshold rectangles are rejected. In each other
thedo 166:3a9487d57a5c 149 cluster, the average rectangle is computed and put into the output rectangle list.
thedo 166:3a9487d57a5c 150 */
thedo 166:3a9487d57a5c 151 CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, int groupThreshold, double eps = 0.2);
thedo 166:3a9487d57a5c 152 /** @overload */
thedo 166:3a9487d57a5c 153 CV_EXPORTS_W void groupRectangles(CV_IN_OUT std::vector<Rect>& rectList, CV_OUT std::vector<int>& weights,
thedo 166:3a9487d57a5c 154 int groupThreshold, double eps = 0.2);
thedo 166:3a9487d57a5c 155 /** @overload */
thedo 166:3a9487d57a5c 156 CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, int groupThreshold,
thedo 166:3a9487d57a5c 157 double eps, std::vector<int>* weights, std::vector<double>* levelWeights );
thedo 166:3a9487d57a5c 158 /** @overload */
thedo 166:3a9487d57a5c 159 CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, std::vector<int>& rejectLevels,
thedo 166:3a9487d57a5c 160 std::vector<double>& levelWeights, int groupThreshold, double eps = 0.2);
thedo 166:3a9487d57a5c 161 /** @overload */
thedo 166:3a9487d57a5c 162 CV_EXPORTS void groupRectangles_meanshift(std::vector<Rect>& rectList, std::vector<double>& foundWeights,
thedo 166:3a9487d57a5c 163 std::vector<double>& foundScales,
thedo 166:3a9487d57a5c 164 double detectThreshold = 0.0, Size winDetSize = Size(64, 128));
thedo 166:3a9487d57a5c 165
thedo 166:3a9487d57a5c 166 template<> CV_EXPORTS void DefaultDeleter<CvHaarClassifierCascade>::operator ()(CvHaarClassifierCascade* obj) const;
thedo 166:3a9487d57a5c 167
thedo 166:3a9487d57a5c 168 enum { CASCADE_DO_CANNY_PRUNING = 1,
thedo 166:3a9487d57a5c 169 CASCADE_SCALE_IMAGE = 2,
thedo 166:3a9487d57a5c 170 CASCADE_FIND_BIGGEST_OBJECT = 4,
thedo 166:3a9487d57a5c 171 CASCADE_DO_ROUGH_SEARCH = 8
thedo 166:3a9487d57a5c 172 };
thedo 166:3a9487d57a5c 173
thedo 166:3a9487d57a5c 174 class CV_EXPORTS_W BaseCascadeClassifier : public Algorithm
thedo 166:3a9487d57a5c 175 {
thedo 166:3a9487d57a5c 176 public:
thedo 166:3a9487d57a5c 177 virtual ~BaseCascadeClassifier();
thedo 166:3a9487d57a5c 178 virtual bool empty() const = 0;
thedo 166:3a9487d57a5c 179 virtual bool load( const String& filename ) = 0;
thedo 166:3a9487d57a5c 180 virtual void detectMultiScale( InputArray image,
thedo 166:3a9487d57a5c 181 CV_OUT std::vector<Rect>& objects,
thedo 166:3a9487d57a5c 182 double scaleFactor,
thedo 166:3a9487d57a5c 183 int minNeighbors, int flags,
thedo 166:3a9487d57a5c 184 Size minSize, Size maxSize ) = 0;
thedo 166:3a9487d57a5c 185
thedo 166:3a9487d57a5c 186 virtual void detectMultiScale( InputArray image,
thedo 166:3a9487d57a5c 187 CV_OUT std::vector<Rect>& objects,
thedo 166:3a9487d57a5c 188 CV_OUT std::vector<int>& numDetections,
thedo 166:3a9487d57a5c 189 double scaleFactor,
thedo 166:3a9487d57a5c 190 int minNeighbors, int flags,
thedo 166:3a9487d57a5c 191 Size minSize, Size maxSize ) = 0;
thedo 166:3a9487d57a5c 192
thedo 166:3a9487d57a5c 193 virtual void detectMultiScale( InputArray image,
thedo 166:3a9487d57a5c 194 CV_OUT std::vector<Rect>& objects,
thedo 166:3a9487d57a5c 195 CV_OUT std::vector<int>& rejectLevels,
thedo 166:3a9487d57a5c 196 CV_OUT std::vector<double>& levelWeights,
thedo 166:3a9487d57a5c 197 double scaleFactor,
thedo 166:3a9487d57a5c 198 int minNeighbors, int flags,
thedo 166:3a9487d57a5c 199 Size minSize, Size maxSize,
thedo 166:3a9487d57a5c 200 bool outputRejectLevels ) = 0;
thedo 166:3a9487d57a5c 201
thedo 166:3a9487d57a5c 202 virtual bool isOldFormatCascade() const = 0;
thedo 166:3a9487d57a5c 203 virtual Size getOriginalWindowSize() const = 0;
thedo 166:3a9487d57a5c 204 virtual int getFeatureType() const = 0;
thedo 166:3a9487d57a5c 205 virtual void* getOldCascade() = 0;
thedo 166:3a9487d57a5c 206
thedo 166:3a9487d57a5c 207 class CV_EXPORTS MaskGenerator
thedo 166:3a9487d57a5c 208 {
thedo 166:3a9487d57a5c 209 public:
thedo 166:3a9487d57a5c 210 virtual ~MaskGenerator() {}
thedo 166:3a9487d57a5c 211 virtual Mat generateMask(const Mat& src)=0;
thedo 166:3a9487d57a5c 212 virtual void initializeMask(const Mat& /*src*/) { }
thedo 166:3a9487d57a5c 213 };
thedo 166:3a9487d57a5c 214 virtual void setMaskGenerator(const Ptr<MaskGenerator>& maskGenerator) = 0;
thedo 166:3a9487d57a5c 215 virtual Ptr<MaskGenerator> getMaskGenerator() = 0;
thedo 166:3a9487d57a5c 216 };
thedo 166:3a9487d57a5c 217
thedo 166:3a9487d57a5c 218 /** @brief Cascade classifier class for object detection.
thedo 166:3a9487d57a5c 219 */
thedo 166:3a9487d57a5c 220 class CV_EXPORTS_W CascadeClassifier
thedo 166:3a9487d57a5c 221 {
thedo 166:3a9487d57a5c 222 public:
thedo 166:3a9487d57a5c 223 CV_WRAP CascadeClassifier();
thedo 166:3a9487d57a5c 224 /** @brief Loads a classifier from a file.
thedo 166:3a9487d57a5c 225
thedo 166:3a9487d57a5c 226 @param filename Name of the file from which the classifier is loaded.
thedo 166:3a9487d57a5c 227 */
thedo 166:3a9487d57a5c 228 CV_WRAP CascadeClassifier(const String& filename);
thedo 166:3a9487d57a5c 229 ~CascadeClassifier();
thedo 166:3a9487d57a5c 230 /** @brief Checks whether the classifier has been loaded.
thedo 166:3a9487d57a5c 231 */
thedo 166:3a9487d57a5c 232 CV_WRAP bool empty() const;
thedo 166:3a9487d57a5c 233 /** @brief Loads a classifier from a file.
thedo 166:3a9487d57a5c 234
thedo 166:3a9487d57a5c 235 @param filename Name of the file from which the classifier is loaded. The file may contain an old
thedo 166:3a9487d57a5c 236 HAAR classifier trained by the haartraining application or a new cascade classifier trained by the
thedo 166:3a9487d57a5c 237 traincascade application.
thedo 166:3a9487d57a5c 238 */
thedo 166:3a9487d57a5c 239 CV_WRAP bool load( const String& filename );
thedo 166:3a9487d57a5c 240 /** @brief Reads a classifier from a FileStorage node.
thedo 166:3a9487d57a5c 241
thedo 166:3a9487d57a5c 242 @note The file may contain a new cascade classifier (trained traincascade application) only.
thedo 166:3a9487d57a5c 243 */
thedo 166:3a9487d57a5c 244 CV_WRAP bool read( const FileNode& node );
thedo 166:3a9487d57a5c 245
thedo 166:3a9487d57a5c 246 /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list
thedo 166:3a9487d57a5c 247 of rectangles.
thedo 166:3a9487d57a5c 248
thedo 166:3a9487d57a5c 249 @param image Matrix of the type CV_8U containing an image where objects are detected.
thedo 166:3a9487d57a5c 250 @param objects Vector of rectangles where each rectangle contains the detected object, the
thedo 166:3a9487d57a5c 251 rectangles may be partially outside the original image.
thedo 166:3a9487d57a5c 252 @param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
thedo 166:3a9487d57a5c 253 @param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
thedo 166:3a9487d57a5c 254 to retain it.
thedo 166:3a9487d57a5c 255 @param flags Parameter with the same meaning for an old cascade as in the function
thedo 166:3a9487d57a5c 256 cvHaarDetectObjects. It is not used for a new cascade.
thedo 166:3a9487d57a5c 257 @param minSize Minimum possible object size. Objects smaller than that are ignored.
thedo 166:3a9487d57a5c 258 @param maxSize Maximum possible object size. Objects larger than that are ignored.
thedo 166:3a9487d57a5c 259
thedo 166:3a9487d57a5c 260 The function is parallelized with the TBB library.
thedo 166:3a9487d57a5c 261
thedo 166:3a9487d57a5c 262 @note
thedo 166:3a9487d57a5c 263 - (Python) A face detection example using cascade classifiers can be found at
thedo 166:3a9487d57a5c 264 opencv_source_code/samples/python/facedetect.py
thedo 166:3a9487d57a5c 265 */
thedo 166:3a9487d57a5c 266 CV_WRAP void detectMultiScale( InputArray image,
thedo 166:3a9487d57a5c 267 CV_OUT std::vector<Rect>& objects,
thedo 166:3a9487d57a5c 268 double scaleFactor = 1.1,
thedo 166:3a9487d57a5c 269 int minNeighbors = 3, int flags = 0,
thedo 166:3a9487d57a5c 270 Size minSize = Size(),
thedo 166:3a9487d57a5c 271 Size maxSize = Size() );
thedo 166:3a9487d57a5c 272
thedo 166:3a9487d57a5c 273 /** @overload
thedo 166:3a9487d57a5c 274 @param image Matrix of the type CV_8U containing an image where objects are detected.
thedo 166:3a9487d57a5c 275 @param objects Vector of rectangles where each rectangle contains the detected object, the
thedo 166:3a9487d57a5c 276 rectangles may be partially outside the original image.
thedo 166:3a9487d57a5c 277 @param numDetections Vector of detection numbers for the corresponding objects. An object's number
thedo 166:3a9487d57a5c 278 of detections is the number of neighboring positively classified rectangles that were joined
thedo 166:3a9487d57a5c 279 together to form the object.
thedo 166:3a9487d57a5c 280 @param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
thedo 166:3a9487d57a5c 281 @param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
thedo 166:3a9487d57a5c 282 to retain it.
thedo 166:3a9487d57a5c 283 @param flags Parameter with the same meaning for an old cascade as in the function
thedo 166:3a9487d57a5c 284 cvHaarDetectObjects. It is not used for a new cascade.
thedo 166:3a9487d57a5c 285 @param minSize Minimum possible object size. Objects smaller than that are ignored.
thedo 166:3a9487d57a5c 286 @param maxSize Maximum possible object size. Objects larger than that are ignored.
thedo 166:3a9487d57a5c 287 */
thedo 166:3a9487d57a5c 288 CV_WRAP_AS(detectMultiScale2) void detectMultiScale( InputArray image,
thedo 166:3a9487d57a5c 289 CV_OUT std::vector<Rect>& objects,
thedo 166:3a9487d57a5c 290 CV_OUT std::vector<int>& numDetections,
thedo 166:3a9487d57a5c 291 double scaleFactor=1.1,
thedo 166:3a9487d57a5c 292 int minNeighbors=3, int flags=0,
thedo 166:3a9487d57a5c 293 Size minSize=Size(),
thedo 166:3a9487d57a5c 294 Size maxSize=Size() );
thedo 166:3a9487d57a5c 295
thedo 166:3a9487d57a5c 296 /** @overload
thedo 166:3a9487d57a5c 297 if `outputRejectLevels` is `true` returns `rejectLevels` and `levelWeights`
thedo 166:3a9487d57a5c 298 */
thedo 166:3a9487d57a5c 299 CV_WRAP_AS(detectMultiScale3) void detectMultiScale( InputArray image,
thedo 166:3a9487d57a5c 300 CV_OUT std::vector<Rect>& objects,
thedo 166:3a9487d57a5c 301 CV_OUT std::vector<int>& rejectLevels,
thedo 166:3a9487d57a5c 302 CV_OUT std::vector<double>& levelWeights,
thedo 166:3a9487d57a5c 303 double scaleFactor = 1.1,
thedo 166:3a9487d57a5c 304 int minNeighbors = 3, int flags = 0,
thedo 166:3a9487d57a5c 305 Size minSize = Size(),
thedo 166:3a9487d57a5c 306 Size maxSize = Size(),
thedo 166:3a9487d57a5c 307 bool outputRejectLevels = false );
thedo 166:3a9487d57a5c 308
thedo 166:3a9487d57a5c 309 CV_WRAP bool isOldFormatCascade() const;
thedo 166:3a9487d57a5c 310 CV_WRAP Size getOriginalWindowSize() const;
thedo 166:3a9487d57a5c 311 CV_WRAP int getFeatureType() const;
thedo 166:3a9487d57a5c 312 void* getOldCascade();
thedo 166:3a9487d57a5c 313
thedo 166:3a9487d57a5c 314 CV_WRAP static bool convert(const String& oldcascade, const String& newcascade);
thedo 166:3a9487d57a5c 315
thedo 166:3a9487d57a5c 316 void setMaskGenerator(const Ptr<BaseCascadeClassifier::MaskGenerator>& maskGenerator);
thedo 166:3a9487d57a5c 317 Ptr<BaseCascadeClassifier::MaskGenerator> getMaskGenerator();
thedo 166:3a9487d57a5c 318
thedo 166:3a9487d57a5c 319 Ptr<BaseCascadeClassifier> cc;
thedo 166:3a9487d57a5c 320 };
thedo 166:3a9487d57a5c 321
thedo 166:3a9487d57a5c 322 CV_EXPORTS Ptr<BaseCascadeClassifier::MaskGenerator> createFaceDetectionMaskGenerator();
thedo 166:3a9487d57a5c 323
thedo 166:3a9487d57a5c 324 //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
thedo 166:3a9487d57a5c 325
thedo 166:3a9487d57a5c 326 //! struct for detection region of interest (ROI)
thedo 166:3a9487d57a5c 327 struct DetectionROI
thedo 166:3a9487d57a5c 328 {
thedo 166:3a9487d57a5c 329 //! scale(size) of the bounding box
thedo 166:3a9487d57a5c 330 double scale;
thedo 166:3a9487d57a5c 331 //! set of requrested locations to be evaluated
thedo 166:3a9487d57a5c 332 std::vector<cv::Point> locations;
thedo 166:3a9487d57a5c 333 //! vector that will contain confidence values for each location
thedo 166:3a9487d57a5c 334 std::vector<double> confidences;
thedo 166:3a9487d57a5c 335 };
thedo 166:3a9487d57a5c 336
thedo 166:3a9487d57a5c 337 struct CV_EXPORTS_W HOGDescriptor
thedo 166:3a9487d57a5c 338 {
thedo 166:3a9487d57a5c 339 public:
thedo 166:3a9487d57a5c 340 enum { L2Hys = 0
thedo 166:3a9487d57a5c 341 };
thedo 166:3a9487d57a5c 342 enum { DEFAULT_NLEVELS = 64
thedo 166:3a9487d57a5c 343 };
thedo 166:3a9487d57a5c 344
thedo 166:3a9487d57a5c 345 CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8),
thedo 166:3a9487d57a5c 346 cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1),
thedo 166:3a9487d57a5c 347 histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true),
thedo 166:3a9487d57a5c 348 free_coef(-1.f), nlevels(HOGDescriptor::DEFAULT_NLEVELS), signedGradient(false)
thedo 166:3a9487d57a5c 349 {}
thedo 166:3a9487d57a5c 350
thedo 166:3a9487d57a5c 351 CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride,
thedo 166:3a9487d57a5c 352 Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1,
thedo 166:3a9487d57a5c 353 int _histogramNormType=HOGDescriptor::L2Hys,
thedo 166:3a9487d57a5c 354 double _L2HysThreshold=0.2, bool _gammaCorrection=false,
thedo 166:3a9487d57a5c 355 int _nlevels=HOGDescriptor::DEFAULT_NLEVELS, bool _signedGradient=false)
thedo 166:3a9487d57a5c 356 : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize),
thedo 166:3a9487d57a5c 357 nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma),
thedo 166:3a9487d57a5c 358 histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold),
thedo 166:3a9487d57a5c 359 gammaCorrection(_gammaCorrection), free_coef(-1.f), nlevels(_nlevels), signedGradient(_signedGradient)
thedo 166:3a9487d57a5c 360 {}
thedo 166:3a9487d57a5c 361
thedo 166:3a9487d57a5c 362 CV_WRAP HOGDescriptor(const String& filename)
thedo 166:3a9487d57a5c 363 {
thedo 166:3a9487d57a5c 364 load(filename);
thedo 166:3a9487d57a5c 365 }
thedo 166:3a9487d57a5c 366
thedo 166:3a9487d57a5c 367 HOGDescriptor(const HOGDescriptor& d)
thedo 166:3a9487d57a5c 368 {
thedo 166:3a9487d57a5c 369 d.copyTo(*this);
thedo 166:3a9487d57a5c 370 }
thedo 166:3a9487d57a5c 371
thedo 166:3a9487d57a5c 372 virtual ~HOGDescriptor() {}
thedo 166:3a9487d57a5c 373
thedo 166:3a9487d57a5c 374 CV_WRAP size_t getDescriptorSize() const;
thedo 166:3a9487d57a5c 375 CV_WRAP bool checkDetectorSize() const;
thedo 166:3a9487d57a5c 376 CV_WRAP double getWinSigma() const;
thedo 166:3a9487d57a5c 377
thedo 166:3a9487d57a5c 378 CV_WRAP virtual void setSVMDetector(InputArray _svmdetector);
thedo 166:3a9487d57a5c 379
thedo 166:3a9487d57a5c 380 virtual bool read(FileNode& fn);
thedo 166:3a9487d57a5c 381 virtual void write(FileStorage& fs, const String& objname) const;
thedo 166:3a9487d57a5c 382
thedo 166:3a9487d57a5c 383 CV_WRAP virtual bool load(const String& filename, const String& objname = String());
thedo 166:3a9487d57a5c 384 CV_WRAP virtual void save(const String& filename, const String& objname = String()) const;
thedo 166:3a9487d57a5c 385 virtual void copyTo(HOGDescriptor& c) const;
thedo 166:3a9487d57a5c 386
thedo 166:3a9487d57a5c 387 CV_WRAP virtual void compute(InputArray img,
thedo 166:3a9487d57a5c 388 CV_OUT std::vector<float>& descriptors,
thedo 166:3a9487d57a5c 389 Size winStride = Size(), Size padding = Size(),
thedo 166:3a9487d57a5c 390 const std::vector<Point>& locations = std::vector<Point>()) const;
thedo 166:3a9487d57a5c 391
thedo 166:3a9487d57a5c 392 //! with found weights output
thedo 166:3a9487d57a5c 393 CV_WRAP virtual void detect(const Mat& img, CV_OUT std::vector<Point>& foundLocations,
thedo 166:3a9487d57a5c 394 CV_OUT std::vector<double>& weights,
thedo 166:3a9487d57a5c 395 double hitThreshold = 0, Size winStride = Size(),
thedo 166:3a9487d57a5c 396 Size padding = Size(),
thedo 166:3a9487d57a5c 397 const std::vector<Point>& searchLocations = std::vector<Point>()) const;
thedo 166:3a9487d57a5c 398 //! without found weights output
thedo 166:3a9487d57a5c 399 virtual void detect(const Mat& img, CV_OUT std::vector<Point>& foundLocations,
thedo 166:3a9487d57a5c 400 double hitThreshold = 0, Size winStride = Size(),
thedo 166:3a9487d57a5c 401 Size padding = Size(),
thedo 166:3a9487d57a5c 402 const std::vector<Point>& searchLocations=std::vector<Point>()) const;
thedo 166:3a9487d57a5c 403
thedo 166:3a9487d57a5c 404 //! with result weights output
thedo 166:3a9487d57a5c 405 CV_WRAP virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
thedo 166:3a9487d57a5c 406 CV_OUT std::vector<double>& foundWeights, double hitThreshold = 0,
thedo 166:3a9487d57a5c 407 Size winStride = Size(), Size padding = Size(), double scale = 1.05,
thedo 166:3a9487d57a5c 408 double finalThreshold = 2.0,bool useMeanshiftGrouping = false) const;
thedo 166:3a9487d57a5c 409 //! without found weights output
thedo 166:3a9487d57a5c 410 virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
thedo 166:3a9487d57a5c 411 double hitThreshold = 0, Size winStride = Size(),
thedo 166:3a9487d57a5c 412 Size padding = Size(), double scale = 1.05,
thedo 166:3a9487d57a5c 413 double finalThreshold = 2.0, bool useMeanshiftGrouping = false) const;
thedo 166:3a9487d57a5c 414
thedo 166:3a9487d57a5c 415 CV_WRAP virtual void computeGradient(const Mat& img, CV_OUT Mat& grad, CV_OUT Mat& angleOfs,
thedo 166:3a9487d57a5c 416 Size paddingTL = Size(), Size paddingBR = Size()) const;
thedo 166:3a9487d57a5c 417
thedo 166:3a9487d57a5c 418 CV_WRAP static std::vector<float> getDefaultPeopleDetector();
thedo 166:3a9487d57a5c 419 CV_WRAP static std::vector<float> getDaimlerPeopleDetector();
thedo 166:3a9487d57a5c 420
thedo 166:3a9487d57a5c 421 CV_PROP Size winSize;
thedo 166:3a9487d57a5c 422 CV_PROP Size blockSize;
thedo 166:3a9487d57a5c 423 CV_PROP Size blockStride;
thedo 166:3a9487d57a5c 424 CV_PROP Size cellSize;
thedo 166:3a9487d57a5c 425 CV_PROP int nbins;
thedo 166:3a9487d57a5c 426 CV_PROP int derivAperture;
thedo 166:3a9487d57a5c 427 CV_PROP double winSigma;
thedo 166:3a9487d57a5c 428 CV_PROP int histogramNormType;
thedo 166:3a9487d57a5c 429 CV_PROP double L2HysThreshold;
thedo 166:3a9487d57a5c 430 CV_PROP bool gammaCorrection;
thedo 166:3a9487d57a5c 431 CV_PROP std::vector<float> svmDetector;
thedo 166:3a9487d57a5c 432 UMat oclSvmDetector;
thedo 166:3a9487d57a5c 433 float free_coef;
thedo 166:3a9487d57a5c 434 CV_PROP int nlevels;
thedo 166:3a9487d57a5c 435 CV_PROP bool signedGradient;
thedo 166:3a9487d57a5c 436
thedo 166:3a9487d57a5c 437
thedo 166:3a9487d57a5c 438 //! evaluate specified ROI and return confidence value for each location
thedo 166:3a9487d57a5c 439 virtual void detectROI(const cv::Mat& img, const std::vector<cv::Point> &locations,
thedo 166:3a9487d57a5c 440 CV_OUT std::vector<cv::Point>& foundLocations, CV_OUT std::vector<double>& confidences,
thedo 166:3a9487d57a5c 441 double hitThreshold = 0, cv::Size winStride = Size(),
thedo 166:3a9487d57a5c 442 cv::Size padding = Size()) const;
thedo 166:3a9487d57a5c 443
thedo 166:3a9487d57a5c 444 //! evaluate specified ROI and return confidence value for each location in multiple scales
thedo 166:3a9487d57a5c 445 virtual void detectMultiScaleROI(const cv::Mat& img,
thedo 166:3a9487d57a5c 446 CV_OUT std::vector<cv::Rect>& foundLocations,
thedo 166:3a9487d57a5c 447 std::vector<DetectionROI>& locations,
thedo 166:3a9487d57a5c 448 double hitThreshold = 0,
thedo 166:3a9487d57a5c 449 int groupThreshold = 0) const;
thedo 166:3a9487d57a5c 450
thedo 166:3a9487d57a5c 451 //! read/parse Dalal's alt model file
thedo 166:3a9487d57a5c 452 void readALTModel(String modelfile);
thedo 166:3a9487d57a5c 453 void groupRectangles(std::vector<cv::Rect>& rectList, std::vector<double>& weights, int groupThreshold, double eps) const;
thedo 166:3a9487d57a5c 454 };
thedo 166:3a9487d57a5c 455
thedo 166:3a9487d57a5c 456 //! @} objdetect
thedo 166:3a9487d57a5c 457
thedo 166:3a9487d57a5c 458 }
thedo 166:3a9487d57a5c 459
thedo 166:3a9487d57a5c 460 #include "opencv2/objdetect/detection_based_tracker.hpp"
thedo 166:3a9487d57a5c 461
thedo 166:3a9487d57a5c 462 #ifndef DISABLE_OPENCV_24_COMPATIBILITY
thedo 166:3a9487d57a5c 463 #include "opencv2/objdetect/objdetect_c.h"
thedo 166:3a9487d57a5c 464 #endif
thedo 166:3a9487d57a5c 465
thedo 166:3a9487d57a5c 466 #endif
thedo 166:3a9487d57a5c 467