openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

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