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) 2009, Willow Garage Inc., all rights reserved. |
15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
16 | // Third party copyrights are property of their respective owners. |
17 | // |
18 | // Redistribution and use in source and binary forms, with or without modification, |
19 | // are permitted provided that the following conditions are met: |
20 | // |
21 | // * Redistribution's of source code must retain the above copyright notice, |
22 | // this list of conditions and the following disclaimer. |
23 | // |
24 | // * Redistribution's in binary form must reproduce the above copyright notice, |
25 | // this list of conditions and the following disclaimer in the documentation |
26 | // and/or other materials provided with the distribution. |
27 | // |
28 | // * The name of the copyright holders may not be used to endorse or promote products |
29 | // derived from this software without specific prior written permission. |
30 | // |
31 | // This software is provided by the copyright holders and contributors "as is" and |
32 | // any express or implied warranties, including, but not limited to, the implied |
33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
34 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
35 | // indirect, incidental, special, exemplary, or consequential damages |
36 | // (including, but not limited to, procurement of substitute goods or services; |
37 | // loss of use, data, or profits; or business interruption) however caused |
38 | // and on any theory of liability, whether in contract, strict liability, |
39 | // or tort (including negligence or otherwise) arising in any way out of |
40 | // the use of this software, even if advised of the possibility of such damage. |
41 | // |
42 | //M*/ |
43 | |
44 | #ifndef OPENCV_OBJDETECT_HPP |
45 | #define OPENCV_OBJDETECT_HPP |
46 | |
47 | #include "opencv2/core.hpp" |
48 | #include "opencv2/objdetect/aruco_detector.hpp" |
49 | #include "opencv2/objdetect/graphical_code_detector.hpp" |
50 | |
51 | /** |
52 | @defgroup objdetect Object Detection |
53 | |
54 | @{ |
55 | @defgroup objdetect_cascade_classifier Cascade Classifier for Object Detection |
56 | |
57 | The object detector described below has been initially proposed by Paul Viola @cite Viola01 and |
58 | improved by Rainer Lienhart @cite Lienhart02 . |
59 | |
60 | First, a classifier (namely a *cascade of boosted classifiers working with haar-like features*) is |
61 | trained with a few hundred sample views of a particular object (i.e., a face or a car), called |
62 | positive examples, that are scaled to the same size (say, 20x20), and negative examples - arbitrary |
63 | images of the same size. |
64 | |
65 | After a classifier is trained, it can be applied to a region of interest (of the same size as used |
66 | during the training) in an input image. The classifier outputs a "1" if the region is likely to show |
67 | the object (i.e., face/car), and "0" otherwise. To search for the object in the whole image one can |
68 | move the search window across the image and check every location using the classifier. The |
69 | classifier is designed so that it can be easily "resized" in order to be able to find the objects of |
70 | interest at different sizes, which is more efficient than resizing the image itself. So, to find an |
71 | object of an unknown size in the image the scan procedure should be done several times at different |
72 | scales. |
73 | |
74 | The word "cascade" in the classifier name means that the resultant classifier consists of several |
75 | simpler classifiers (*stages*) that are applied subsequently to a region of interest until at some |
76 | stage the candidate is rejected or all the stages are passed. The word "boosted" means that the |
77 | classifiers at every stage of the cascade are complex themselves and they are built out of basic |
78 | classifiers using one of four different boosting techniques (weighted voting). Currently Discrete |
79 | Adaboost, Real Adaboost, Gentle Adaboost and Logitboost are supported. The basic classifiers are |
80 | decision-tree classifiers with at least 2 leaves. Haar-like features are the input to the basic |
81 | classifiers, and are calculated as described below. The current algorithm uses the following |
82 | Haar-like features: |
83 | |
84 |  |
85 | |
86 | The feature used in a particular classifier is specified by its shape (1a, 2b etc.), position within |
87 | the region of interest and the scale (this scale is not the same as the scale used at the detection |
88 | stage, though these two scales are multiplied). For example, in the case of the third line feature |
89 | (2c) the response is calculated as the difference between the sum of image pixels under the |
90 | rectangle covering the whole feature (including the two white stripes and the black stripe in the |
91 | middle) and the sum of the image pixels under the black stripe multiplied by 3 in order to |
92 | compensate for the differences in the size of areas. The sums of pixel values over a rectangular |
93 | regions are calculated rapidly using integral images (see below and the integral description). |
94 | |
95 | Check @ref tutorial_cascade_classifier "the corresponding tutorial" for more details. |
96 | |
97 | The following reference is for the detection part only. There is a separate application called |
98 | opencv_traincascade that can train a cascade of boosted classifiers from a set of samples. |
99 | |
100 | @note In the new C++ interface it is also possible to use LBP (local binary pattern) features in |
101 | addition to Haar-like features. .. [Viola01] Paul Viola and Michael J. Jones. Rapid Object Detection |
102 | using a Boosted Cascade of Simple Features. IEEE CVPR, 2001. The paper is available online at |
103 | <https://github.com/SvHey/thesis/blob/master/Literature/ObjectDetection/violaJones_CVPR2001.pdf> |
104 | |
105 | @defgroup objdetect_hog HOG (Histogram of Oriented Gradients) descriptor and object detector |
106 | @defgroup objdetect_barcode Barcode detection and decoding |
107 | @defgroup objdetect_qrcode QRCode detection and encoding |
108 | @defgroup objdetect_dnn_face DNN-based face detection and recognition |
109 | |
110 | Check @ref tutorial_dnn_face "the corresponding tutorial" for more details. |
111 | |
112 | @defgroup objdetect_common Common functions and classes |
113 | @defgroup objdetect_aruco ArUco markers and boards detection for robust camera pose estimation |
114 | @{ |
115 | ArUco Marker Detection |
116 | Square fiducial markers (also known as Augmented Reality Markers) are useful for easy, |
117 | fast and robust camera pose estimation. |
118 | |
119 | The main functionality of ArucoDetector class is detection of markers in an image. If the markers are grouped |
120 | as a board, then you can try to recover the missing markers with ArucoDetector::refineDetectedMarkers(). |
121 | ArUco markers can also be used for advanced chessboard corner finding. To do this, group the markers in the |
122 | CharucoBoard and find the corners of the chessboard with the CharucoDetector::detectBoard(). |
123 | |
124 | The implementation is based on the ArUco Library by R. Muñoz-Salinas and S. Garrido-Jurado @cite Aruco2014. |
125 | |
126 | Markers can also be detected based on the AprilTag 2 @cite wang2016iros fiducial detection method. |
127 | |
128 | @sa @cite Aruco2014 |
129 | This code has been originally developed by Sergio Garrido-Jurado as a project |
130 | for Google Summer of Code 2015 (GSoC 15). |
131 | @} |
132 | |
133 | @} |
134 | */ |
135 | |
136 | typedef struct CvHaarClassifierCascade CvHaarClassifierCascade; |
137 | |
138 | namespace cv |
139 | { |
140 | |
141 | //! @addtogroup objdetect_common |
142 | //! @{ |
143 | |
144 | ///////////////////////////// Object Detection //////////////////////////// |
145 | |
146 | /** @brief This class is used for grouping object candidates detected by Cascade Classifier, HOG etc. |
147 | |
148 | instance of the class is to be passed to cv::partition |
149 | */ |
150 | class CV_EXPORTS SimilarRects |
151 | { |
152 | public: |
153 | SimilarRects(double _eps) : eps(_eps) {} |
154 | inline bool operator()(const Rect& r1, const Rect& r2) const |
155 | { |
156 | double delta = eps * ((std::min)(a: r1.width, b: r2.width) + (std::min)(a: r1.height, b: r2.height)) * 0.5; |
157 | return std::abs(x: r1.x - r2.x) <= delta && |
158 | std::abs(x: r1.y - r2.y) <= delta && |
159 | std::abs(x: r1.x + r1.width - r2.x - r2.width) <= delta && |
160 | std::abs(x: r1.y + r1.height - r2.y - r2.height) <= delta; |
161 | } |
162 | double eps; |
163 | }; |
164 | |
165 | /** @brief Groups the object candidate rectangles. |
166 | |
167 | @param rectList Input/output vector of rectangles. Output vector includes retained and grouped |
168 | rectangles. (The Python list is not modified in place.) |
169 | @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a |
170 | group of rectangles to retain it. |
171 | @param eps Relative difference between sides of the rectangles to merge them into a group. |
172 | |
173 | The function is a wrapper for the generic function partition . It clusters all the input rectangles |
174 | using the rectangle equivalence criteria that combines rectangles with similar sizes and similar |
175 | locations. The similarity is defined by eps. When eps=0 , no clustering is done at all. If |
176 | \f$\texttt{eps}\rightarrow +\inf\f$ , all the rectangles are put in one cluster. Then, the small |
177 | clusters containing less than or equal to groupThreshold rectangles are rejected. In each other |
178 | cluster, the average rectangle is computed and put into the output rectangle list. |
179 | */ |
180 | CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, int groupThreshold, double eps = 0.2); |
181 | /** @overload */ |
182 | CV_EXPORTS_W void groupRectangles(CV_IN_OUT std::vector<Rect>& rectList, CV_OUT std::vector<int>& weights, |
183 | int groupThreshold, double eps = 0.2); |
184 | /** @overload */ |
185 | CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, int groupThreshold, |
186 | double eps, std::vector<int>* weights, std::vector<double>* levelWeights ); |
187 | /** @overload */ |
188 | CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, std::vector<int>& rejectLevels, |
189 | std::vector<double>& levelWeights, int groupThreshold, double eps = 0.2); |
190 | /** @overload */ |
191 | CV_EXPORTS void groupRectangles_meanshift(std::vector<Rect>& rectList, std::vector<double>& foundWeights, |
192 | std::vector<double>& foundScales, |
193 | double detectThreshold = 0.0, Size winDetSize = Size(64, 128)); |
194 | //! @} |
195 | |
196 | //! @addtogroup objdetect_cascade_classifier |
197 | //! @{ |
198 | |
199 | template<> struct DefaultDeleter<CvHaarClassifierCascade>{ CV_EXPORTS void operator ()(CvHaarClassifierCascade* obj) const; }; |
200 | |
201 | enum { CASCADE_DO_CANNY_PRUNING = 1, |
202 | CASCADE_SCALE_IMAGE = 2, |
203 | CASCADE_FIND_BIGGEST_OBJECT = 4, |
204 | CASCADE_DO_ROUGH_SEARCH = 8 |
205 | }; |
206 | |
207 | class CV_EXPORTS_W BaseCascadeClassifier : public Algorithm |
208 | { |
209 | public: |
210 | virtual ~BaseCascadeClassifier(); |
211 | virtual bool empty() const CV_OVERRIDE = 0; |
212 | virtual bool load( const String& filename ) = 0; |
213 | virtual void detectMultiScale( InputArray image, |
214 | CV_OUT std::vector<Rect>& objects, |
215 | double scaleFactor, |
216 | int minNeighbors, int flags, |
217 | Size minSize, Size maxSize ) = 0; |
218 | |
219 | virtual void detectMultiScale( InputArray image, |
220 | CV_OUT std::vector<Rect>& objects, |
221 | CV_OUT std::vector<int>& numDetections, |
222 | double scaleFactor, |
223 | int minNeighbors, int flags, |
224 | Size minSize, Size maxSize ) = 0; |
225 | |
226 | virtual void detectMultiScale( InputArray image, |
227 | CV_OUT std::vector<Rect>& objects, |
228 | CV_OUT std::vector<int>& rejectLevels, |
229 | CV_OUT std::vector<double>& levelWeights, |
230 | double scaleFactor, |
231 | int minNeighbors, int flags, |
232 | Size minSize, Size maxSize, |
233 | bool outputRejectLevels ) = 0; |
234 | |
235 | virtual bool isOldFormatCascade() const = 0; |
236 | virtual Size getOriginalWindowSize() const = 0; |
237 | virtual int getFeatureType() const = 0; |
238 | virtual void* getOldCascade() = 0; |
239 | |
240 | class CV_EXPORTS MaskGenerator |
241 | { |
242 | public: |
243 | virtual ~MaskGenerator() {} |
244 | virtual Mat generateMask(const Mat& src)=0; |
245 | virtual void initializeMask(const Mat& /*src*/) { } |
246 | }; |
247 | virtual void setMaskGenerator(const Ptr<MaskGenerator>& maskGenerator) = 0; |
248 | virtual Ptr<MaskGenerator> getMaskGenerator() = 0; |
249 | }; |
250 | |
251 | /** @example samples/cpp/facedetect.cpp |
252 | This program demonstrates usage of the Cascade classifier class |
253 | \image html Cascade_Classifier_Tutorial_Result_Haar.jpg "Sample screenshot" width=321 height=254 |
254 | */ |
255 | /** @brief Cascade classifier class for object detection. |
256 | */ |
257 | class CV_EXPORTS_W CascadeClassifier |
258 | { |
259 | public: |
260 | CV_WRAP CascadeClassifier(); |
261 | /** @brief Loads a classifier from a file. |
262 | |
263 | @param filename Name of the file from which the classifier is loaded. |
264 | */ |
265 | CV_WRAP CascadeClassifier(const String& filename); |
266 | ~CascadeClassifier(); |
267 | /** @brief Checks whether the classifier has been loaded. |
268 | */ |
269 | CV_WRAP bool empty() const; |
270 | /** @brief Loads a classifier from a file. |
271 | |
272 | @param filename Name of the file from which the classifier is loaded. The file may contain an old |
273 | HAAR classifier trained by the haartraining application or a new cascade classifier trained by the |
274 | traincascade application. |
275 | */ |
276 | CV_WRAP bool load( const String& filename ); |
277 | /** @brief Reads a classifier from a FileStorage node. |
278 | |
279 | @note The file may contain a new cascade classifier (trained by the traincascade application) only. |
280 | */ |
281 | CV_WRAP bool read( const FileNode& node ); |
282 | |
283 | /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list |
284 | of rectangles. |
285 | |
286 | @param image Matrix of the type CV_8U containing an image where objects are detected. |
287 | @param objects Vector of rectangles where each rectangle contains the detected object, the |
288 | rectangles may be partially outside the original image. |
289 | @param scaleFactor Parameter specifying how much the image size is reduced at each image scale. |
290 | @param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have |
291 | to retain it. |
292 | @param flags Parameter with the same meaning for an old cascade as in the function |
293 | cvHaarDetectObjects. It is not used for a new cascade. |
294 | @param minSize Minimum possible object size. Objects smaller than that are ignored. |
295 | @param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale. |
296 | */ |
297 | CV_WRAP void detectMultiScale( InputArray image, |
298 | CV_OUT std::vector<Rect>& objects, |
299 | double scaleFactor = 1.1, |
300 | int minNeighbors = 3, int flags = 0, |
301 | Size minSize = Size(), |
302 | Size maxSize = Size() ); |
303 | |
304 | /** @overload |
305 | @param image Matrix of the type CV_8U containing an image where objects are detected. |
306 | @param objects Vector of rectangles where each rectangle contains the detected object, the |
307 | rectangles may be partially outside the original image. |
308 | @param numDetections Vector of detection numbers for the corresponding objects. An object's number |
309 | of detections is the number of neighboring positively classified rectangles that were joined |
310 | together to form the object. |
311 | @param scaleFactor Parameter specifying how much the image size is reduced at each image scale. |
312 | @param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have |
313 | to retain it. |
314 | @param flags Parameter with the same meaning for an old cascade as in the function |
315 | cvHaarDetectObjects. It is not used for a new cascade. |
316 | @param minSize Minimum possible object size. Objects smaller than that are ignored. |
317 | @param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale. |
318 | */ |
319 | CV_WRAP_AS(detectMultiScale2) void detectMultiScale( InputArray image, |
320 | CV_OUT std::vector<Rect>& objects, |
321 | CV_OUT std::vector<int>& numDetections, |
322 | double scaleFactor=1.1, |
323 | int minNeighbors=3, int flags=0, |
324 | Size minSize=Size(), |
325 | Size maxSize=Size() ); |
326 | |
327 | /** @overload |
328 | This function allows you to retrieve the final stage decision certainty of classification. |
329 | For this, one needs to set `outputRejectLevels` on true and provide the `rejectLevels` and `levelWeights` parameter. |
330 | For each resulting detection, `levelWeights` will then contain the certainty of classification at the final stage. |
331 | This value can then be used to separate strong from weaker classifications. |
332 | |
333 | A code sample on how to use it efficiently can be found below: |
334 | @code |
335 | Mat img; |
336 | vector<double> weights; |
337 | vector<int> levels; |
338 | vector<Rect> detections; |
339 | CascadeClassifier model("/path/to/your/model.xml"); |
340 | model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); |
341 | cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; |
342 | @endcode |
343 | */ |
344 | CV_WRAP_AS(detectMultiScale3) void detectMultiScale( InputArray image, |
345 | CV_OUT std::vector<Rect>& objects, |
346 | CV_OUT std::vector<int>& rejectLevels, |
347 | CV_OUT std::vector<double>& levelWeights, |
348 | double scaleFactor = 1.1, |
349 | int minNeighbors = 3, int flags = 0, |
350 | Size minSize = Size(), |
351 | Size maxSize = Size(), |
352 | bool outputRejectLevels = false ); |
353 | |
354 | CV_WRAP bool isOldFormatCascade() const; |
355 | CV_WRAP Size getOriginalWindowSize() const; |
356 | CV_WRAP int getFeatureType() const; |
357 | void* getOldCascade(); |
358 | |
359 | CV_WRAP static bool convert(const String& oldcascade, const String& newcascade); |
360 | |
361 | void setMaskGenerator(const Ptr<BaseCascadeClassifier::MaskGenerator>& maskGenerator); |
362 | Ptr<BaseCascadeClassifier::MaskGenerator> getMaskGenerator(); |
363 | |
364 | Ptr<BaseCascadeClassifier> cc; |
365 | }; |
366 | |
367 | CV_EXPORTS Ptr<BaseCascadeClassifier::MaskGenerator> createFaceDetectionMaskGenerator(); |
368 | //! @} |
369 | |
370 | //! @addtogroup objdetect_hog |
371 | //! @{ |
372 | //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector ////////////// |
373 | |
374 | //! struct for detection region of interest (ROI) |
375 | struct DetectionROI |
376 | { |
377 | //! scale(size) of the bounding box |
378 | double scale; |
379 | //! set of requested locations to be evaluated |
380 | std::vector<cv::Point> locations; |
381 | //! vector that will contain confidence values for each location |
382 | std::vector<double> confidences; |
383 | }; |
384 | |
385 | /**@brief Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector. |
386 | |
387 | the HOG descriptor algorithm introduced by Navneet Dalal and Bill Triggs @cite Dalal2005 . |
388 | |
389 | useful links: |
390 | |
391 | https://hal.inria.fr/inria-00548512/document/ |
392 | |
393 | https://en.wikipedia.org/wiki/Histogram_of_oriented_gradients |
394 | |
395 | https://software.intel.com/en-us/ipp-dev-reference-histogram-of-oriented-gradients-hog-descriptor |
396 | |
397 | http://www.learnopencv.com/histogram-of-oriented-gradients |
398 | |
399 | http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial |
400 | |
401 | */ |
402 | struct CV_EXPORTS_W HOGDescriptor |
403 | { |
404 | public: |
405 | enum HistogramNormType { L2Hys = 0 //!< Default histogramNormType |
406 | }; |
407 | enum { DEFAULT_NLEVELS = 64 //!< Default nlevels value. |
408 | }; |
409 | enum DescriptorStorageFormat { DESCR_FORMAT_COL_BY_COL, DESCR_FORMAT_ROW_BY_ROW }; |
410 | |
411 | /**@brief Creates the HOG descriptor and detector with default parameters. |
412 | |
413 | aqual to HOGDescriptor(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9 ) |
414 | */ |
415 | CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8), |
416 | cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1), |
417 | histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true), |
418 | free_coef(-1.f), nlevels(HOGDescriptor::DEFAULT_NLEVELS), signedGradient(false) |
419 | {} |
420 | |
421 | /** @overload |
422 | @param _winSize sets winSize with given value. |
423 | @param _blockSize sets blockSize with given value. |
424 | @param _blockStride sets blockStride with given value. |
425 | @param _cellSize sets cellSize with given value. |
426 | @param _nbins sets nbins with given value. |
427 | @param _derivAperture sets derivAperture with given value. |
428 | @param _winSigma sets winSigma with given value. |
429 | @param _histogramNormType sets histogramNormType with given value. |
430 | @param _L2HysThreshold sets L2HysThreshold with given value. |
431 | @param _gammaCorrection sets gammaCorrection with given value. |
432 | @param _nlevels sets nlevels with given value. |
433 | @param _signedGradient sets signedGradient with given value. |
434 | */ |
435 | CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride, |
436 | Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1, |
437 | HOGDescriptor::HistogramNormType _histogramNormType=HOGDescriptor::L2Hys, |
438 | double _L2HysThreshold=0.2, bool _gammaCorrection=false, |
439 | int _nlevels=HOGDescriptor::DEFAULT_NLEVELS, bool _signedGradient=false) |
440 | : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize), |
441 | nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma), |
442 | histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold), |
443 | gammaCorrection(_gammaCorrection), free_coef(-1.f), nlevels(_nlevels), signedGradient(_signedGradient) |
444 | {} |
445 | |
446 | /** @overload |
447 | |
448 | Creates the HOG descriptor and detector and loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file. |
449 | @param filename The file name containing HOGDescriptor properties and coefficients for the linear SVM classifier. |
450 | */ |
451 | CV_WRAP HOGDescriptor(const String& filename) |
452 | { |
453 | load(filename); |
454 | } |
455 | |
456 | /** @overload |
457 | @param d the HOGDescriptor which cloned to create a new one. |
458 | */ |
459 | HOGDescriptor(const HOGDescriptor& d) |
460 | { |
461 | d.copyTo(c&: *this); |
462 | } |
463 | |
464 | /**@brief Default destructor. |
465 | */ |
466 | virtual ~HOGDescriptor() {} |
467 | |
468 | /**@brief Returns the number of coefficients required for the classification. |
469 | */ |
470 | CV_WRAP size_t getDescriptorSize() const; |
471 | |
472 | /** @brief Checks if detector size equal to descriptor size. |
473 | */ |
474 | CV_WRAP bool checkDetectorSize() const; |
475 | |
476 | /** @brief Returns winSigma value |
477 | */ |
478 | CV_WRAP double getWinSigma() const; |
479 | |
480 | /**@example samples/cpp/peopledetect.cpp |
481 | */ |
482 | /**@brief Sets coefficients for the linear SVM classifier. |
483 | @param svmdetector coefficients for the linear SVM classifier. |
484 | */ |
485 | CV_WRAP virtual void setSVMDetector(InputArray svmdetector); |
486 | |
487 | /** @brief Reads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file node. |
488 | @param fn File node |
489 | */ |
490 | virtual bool read(FileNode& fn); |
491 | |
492 | /** @brief Stores HOGDescriptor parameters and coefficients for the linear SVM classifier in a file storage. |
493 | @param fs File storage |
494 | @param objname Object name |
495 | */ |
496 | virtual void write(FileStorage& fs, const String& objname) const; |
497 | |
498 | /** @brief loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file |
499 | @param filename Name of the file to read. |
500 | @param objname The optional name of the node to read (if empty, the first top-level node will be used). |
501 | */ |
502 | CV_WRAP virtual bool load(const String& filename, const String& objname = String()); |
503 | |
504 | /** @brief saves HOGDescriptor parameters and coefficients for the linear SVM classifier to a file |
505 | @param filename File name |
506 | @param objname Object name |
507 | */ |
508 | CV_WRAP virtual void save(const String& filename, const String& objname = String()) const; |
509 | |
510 | /** @brief clones the HOGDescriptor |
511 | @param c cloned HOGDescriptor |
512 | */ |
513 | virtual void copyTo(HOGDescriptor& c) const; |
514 | |
515 | /**@example samples/cpp/train_HOG.cpp |
516 | */ |
517 | /** @brief Computes HOG descriptors of given image. |
518 | @param img Matrix of the type CV_8U containing an image where HOG features will be calculated. |
519 | @param descriptors Matrix of the type CV_32F |
520 | @param winStride Window stride. It must be a multiple of block stride. |
521 | @param padding Padding |
522 | @param locations Vector of Point |
523 | */ |
524 | CV_WRAP virtual void compute(InputArray img, |
525 | CV_OUT std::vector<float>& descriptors, |
526 | Size winStride = Size(), Size padding = Size(), |
527 | const std::vector<Point>& locations = std::vector<Point>()) const; |
528 | |
529 | /** @brief Performs object detection without a multi-scale window. |
530 | @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. |
531 | @param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries. |
532 | @param weights Vector that will contain confidence values for each detected object. |
533 | @param hitThreshold Threshold for the distance between features and SVM classifying plane. |
534 | Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). |
535 | But if the free coefficient is omitted (which is allowed), you can specify it manually here. |
536 | @param winStride Window stride. It must be a multiple of block stride. |
537 | @param padding Padding |
538 | @param searchLocations Vector of Point includes set of requested locations to be evaluated. |
539 | */ |
540 | CV_WRAP virtual void detect(InputArray img, CV_OUT std::vector<Point>& foundLocations, |
541 | CV_OUT std::vector<double>& weights, |
542 | double hitThreshold = 0, Size winStride = Size(), |
543 | Size padding = Size(), |
544 | const std::vector<Point>& searchLocations = std::vector<Point>()) const; |
545 | |
546 | /** @brief Performs object detection without a multi-scale window. |
547 | @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. |
548 | @param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries. |
549 | @param hitThreshold Threshold for the distance between features and SVM classifying plane. |
550 | Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). |
551 | But if the free coefficient is omitted (which is allowed), you can specify it manually here. |
552 | @param winStride Window stride. It must be a multiple of block stride. |
553 | @param padding Padding |
554 | @param searchLocations Vector of Point includes locations to search. |
555 | */ |
556 | virtual void detect(InputArray img, CV_OUT std::vector<Point>& foundLocations, |
557 | double hitThreshold = 0, Size winStride = Size(), |
558 | Size padding = Size(), |
559 | const std::vector<Point>& searchLocations=std::vector<Point>()) const; |
560 | |
561 | /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list |
562 | of rectangles. |
563 | @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. |
564 | @param foundLocations Vector of rectangles where each rectangle contains the detected object. |
565 | @param foundWeights Vector that will contain confidence values for each detected object. |
566 | @param hitThreshold Threshold for the distance between features and SVM classifying plane. |
567 | Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). |
568 | But if the free coefficient is omitted (which is allowed), you can specify it manually here. |
569 | @param winStride Window stride. It must be a multiple of block stride. |
570 | @param padding Padding |
571 | @param scale Coefficient of the detection window increase. |
572 | @param groupThreshold Coefficient to regulate the similarity threshold. When detected, some objects can be covered |
573 | by many rectangles. 0 means not to perform grouping. |
574 | @param useMeanshiftGrouping indicates grouping algorithm |
575 | */ |
576 | CV_WRAP virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations, |
577 | CV_OUT std::vector<double>& foundWeights, double hitThreshold = 0, |
578 | Size winStride = Size(), Size padding = Size(), double scale = 1.05, |
579 | double groupThreshold = 2.0, bool useMeanshiftGrouping = false) const; |
580 | |
581 | /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list |
582 | of rectangles. |
583 | @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. |
584 | @param foundLocations Vector of rectangles where each rectangle contains the detected object. |
585 | @param hitThreshold Threshold for the distance between features and SVM classifying plane. |
586 | Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). |
587 | But if the free coefficient is omitted (which is allowed), you can specify it manually here. |
588 | @param winStride Window stride. It must be a multiple of block stride. |
589 | @param padding Padding |
590 | @param scale Coefficient of the detection window increase. |
591 | @param groupThreshold Coefficient to regulate the similarity threshold. When detected, some objects can be covered |
592 | by many rectangles. 0 means not to perform grouping. |
593 | @param useMeanshiftGrouping indicates grouping algorithm |
594 | */ |
595 | virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations, |
596 | double hitThreshold = 0, Size winStride = Size(), |
597 | Size padding = Size(), double scale = 1.05, |
598 | double groupThreshold = 2.0, bool useMeanshiftGrouping = false) const; |
599 | |
600 | /** @brief Computes gradients and quantized gradient orientations. |
601 | @param img Matrix contains the image to be computed |
602 | @param grad Matrix of type CV_32FC2 contains computed gradients |
603 | @param angleOfs Matrix of type CV_8UC2 contains quantized gradient orientations |
604 | @param paddingTL Padding from top-left |
605 | @param paddingBR Padding from bottom-right |
606 | */ |
607 | CV_WRAP virtual void computeGradient(InputArray img, InputOutputArray grad, InputOutputArray angleOfs, |
608 | Size paddingTL = Size(), Size paddingBR = Size()) const; |
609 | |
610 | /** @brief Returns coefficients of the classifier trained for people detection (for 64x128 windows). |
611 | */ |
612 | CV_WRAP static std::vector<float> getDefaultPeopleDetector(); |
613 | |
614 | /**@example samples/tapi/hog.cpp |
615 | */ |
616 | /** @brief Returns coefficients of the classifier trained for people detection (for 48x96 windows). |
617 | */ |
618 | CV_WRAP static std::vector<float> getDaimlerPeopleDetector(); |
619 | |
620 | //! Detection window size. Align to block size and block stride. Default value is Size(64,128). |
621 | CV_PROP Size winSize; |
622 | |
623 | //! Block size in pixels. Align to cell size. Default value is Size(16,16). |
624 | CV_PROP Size blockSize; |
625 | |
626 | //! Block stride. It must be a multiple of cell size. Default value is Size(8,8). |
627 | CV_PROP Size blockStride; |
628 | |
629 | //! Cell size. Default value is Size(8,8). |
630 | CV_PROP Size cellSize; |
631 | |
632 | //! Number of bins used in the calculation of histogram of gradients. Default value is 9. |
633 | CV_PROP int nbins; |
634 | |
635 | //! not documented |
636 | CV_PROP int derivAperture; |
637 | |
638 | //! Gaussian smoothing window parameter. |
639 | CV_PROP double winSigma; |
640 | |
641 | //! histogramNormType |
642 | CV_PROP HOGDescriptor::HistogramNormType histogramNormType; |
643 | |
644 | //! L2-Hys normalization method shrinkage. |
645 | CV_PROP double L2HysThreshold; |
646 | |
647 | //! Flag to specify whether the gamma correction preprocessing is required or not. |
648 | CV_PROP bool gammaCorrection; |
649 | |
650 | //! coefficients for the linear SVM classifier. |
651 | CV_PROP std::vector<float> svmDetector; |
652 | |
653 | //! coefficients for the linear SVM classifier used when OpenCL is enabled |
654 | UMat oclSvmDetector; |
655 | |
656 | //! not documented |
657 | float free_coef; |
658 | |
659 | //! Maximum number of detection window increases. Default value is 64 |
660 | CV_PROP int nlevels; |
661 | |
662 | //! Indicates signed gradient will be used or not |
663 | CV_PROP bool signedGradient; |
664 | |
665 | /** @brief evaluate specified ROI and return confidence value for each location |
666 | @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. |
667 | @param locations Vector of Point |
668 | @param foundLocations Vector of Point where each Point is detected object's top-left point. |
669 | @param confidences confidences |
670 | @param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually |
671 | it is 0 and should be specified in the detector coefficients (as the last free coefficient). But if |
672 | the free coefficient is omitted (which is allowed), you can specify it manually here |
673 | @param winStride winStride |
674 | @param padding padding |
675 | */ |
676 | virtual void detectROI(InputArray img, const std::vector<cv::Point> &locations, |
677 | CV_OUT std::vector<cv::Point>& foundLocations, CV_OUT std::vector<double>& confidences, |
678 | double hitThreshold = 0, cv::Size winStride = Size(), |
679 | cv::Size padding = Size()) const; |
680 | |
681 | /** @brief evaluate specified ROI and return confidence value for each location in multiple scales |
682 | @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. |
683 | @param foundLocations Vector of rectangles where each rectangle contains the detected object. |
684 | @param locations Vector of DetectionROI |
685 | @param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified |
686 | in the detector coefficients (as the last free coefficient). But if the free coefficient is omitted (which is allowed), you can specify it manually here. |
687 | @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. |
688 | */ |
689 | virtual void detectMultiScaleROI(InputArray img, |
690 | CV_OUT std::vector<cv::Rect>& foundLocations, |
691 | std::vector<DetectionROI>& locations, |
692 | double hitThreshold = 0, |
693 | int groupThreshold = 0) const; |
694 | |
695 | /** @brief Groups the object candidate rectangles. |
696 | @param rectList Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.) |
697 | @param weights Input/output vector of weights of rectangles. Output vector includes weights of retained and grouped rectangles. (The Python list is not modified in place.) |
698 | @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. |
699 | @param eps Relative difference between sides of the rectangles to merge them into a group. |
700 | */ |
701 | void groupRectangles(std::vector<cv::Rect>& rectList, std::vector<double>& weights, int groupThreshold, double eps) const; |
702 | }; |
703 | //! @} |
704 | |
705 | //! @addtogroup objdetect_qrcode |
706 | //! @{ |
707 | |
708 | class CV_EXPORTS_W QRCodeEncoder { |
709 | protected: |
710 | QRCodeEncoder(); // use ::create() |
711 | public: |
712 | virtual ~QRCodeEncoder(); |
713 | |
714 | enum EncodeMode { |
715 | MODE_AUTO = -1, |
716 | MODE_NUMERIC = 1, // 0b0001 |
717 | MODE_ALPHANUMERIC = 2, // 0b0010 |
718 | MODE_BYTE = 4, // 0b0100 |
719 | MODE_ECI = 7, // 0b0111 |
720 | MODE_KANJI = 8, // 0b1000 |
721 | MODE_STRUCTURED_APPEND = 3 // 0b0011 |
722 | }; |
723 | |
724 | enum CorrectionLevel { |
725 | CORRECT_LEVEL_L = 0, |
726 | CORRECT_LEVEL_M = 1, |
727 | CORRECT_LEVEL_Q = 2, |
728 | CORRECT_LEVEL_H = 3 |
729 | }; |
730 | |
731 | enum ECIEncodings { |
732 | ECI_UTF8 = 26 |
733 | }; |
734 | |
735 | /** @brief QR code encoder parameters. */ |
736 | struct CV_EXPORTS_W_SIMPLE Params |
737 | { |
738 | CV_WRAP Params(); |
739 | |
740 | //! The optional version of QR code (by default - maximum possible depending on the length of the string). |
741 | CV_PROP_RW int version; |
742 | |
743 | //! The optional level of error correction (by default - the lowest). |
744 | CV_PROP_RW CorrectionLevel correction_level; |
745 | |
746 | //! The optional encoding mode - Numeric, Alphanumeric, Byte, Kanji, ECI or Structured Append. |
747 | CV_PROP_RW EncodeMode mode; |
748 | |
749 | //! The optional number of QR codes to generate in Structured Append mode. |
750 | CV_PROP_RW int structure_number; |
751 | }; |
752 | |
753 | /** @brief Constructor |
754 | @param parameters QR code encoder parameters QRCodeEncoder::Params |
755 | */ |
756 | static CV_WRAP |
757 | Ptr<QRCodeEncoder> create(const QRCodeEncoder::Params& parameters = QRCodeEncoder::Params()); |
758 | |
759 | /** @brief Generates QR code from input string. |
760 | @param encoded_info Input string to encode. |
761 | @param qrcode Generated QR code. |
762 | */ |
763 | CV_WRAP virtual void encode(const String& encoded_info, OutputArray qrcode) = 0; |
764 | |
765 | /** @brief Generates QR code from input string in Structured Append mode. The encoded message is splitting over a number of QR codes. |
766 | @param encoded_info Input string to encode. |
767 | @param qrcodes Vector of generated QR codes. |
768 | */ |
769 | CV_WRAP virtual void encodeStructuredAppend(const String& encoded_info, OutputArrayOfArrays qrcodes) = 0; |
770 | |
771 | }; |
772 | class CV_EXPORTS_W_SIMPLE QRCodeDetector : public GraphicalCodeDetector |
773 | { |
774 | public: |
775 | CV_WRAP QRCodeDetector(); |
776 | |
777 | /** @brief sets the epsilon used during the horizontal scan of QR code stop marker detection. |
778 | @param epsX Epsilon neighborhood, which allows you to determine the horizontal pattern |
779 | of the scheme 1:1:3:1:1 according to QR code standard. |
780 | */ |
781 | CV_WRAP QRCodeDetector& setEpsX(double epsX); |
782 | /** @brief sets the epsilon used during the vertical scan of QR code stop marker detection. |
783 | @param epsY Epsilon neighborhood, which allows you to determine the vertical pattern |
784 | of the scheme 1:1:3:1:1 according to QR code standard. |
785 | */ |
786 | CV_WRAP QRCodeDetector& setEpsY(double epsY); |
787 | |
788 | /** @brief use markers to improve the position of the corners of the QR code |
789 | * |
790 | * alignmentMarkers using by default |
791 | */ |
792 | CV_WRAP QRCodeDetector& setUseAlignmentMarkers(bool useAlignmentMarkers); |
793 | |
794 | /** @brief Decodes QR code on a curved surface in image once it's found by the detect() method. |
795 | |
796 | Returns UTF8-encoded output string or empty string if the code cannot be decoded. |
797 | @param img grayscale or color (BGR) image containing QR code. |
798 | @param points Quadrangle vertices found by detect() method (or some other algorithm). |
799 | @param straight_qrcode The optional output image containing rectified and binarized QR code |
800 | */ |
801 | CV_WRAP cv::String decodeCurved(InputArray img, InputArray points, OutputArray straight_qrcode = noArray()); |
802 | |
803 | /** @brief Both detects and decodes QR code on a curved surface |
804 | |
805 | @param img grayscale or color (BGR) image containing QR code. |
806 | @param points optional output array of vertices of the found QR code quadrangle. Will be empty if not found. |
807 | @param straight_qrcode The optional output image containing rectified and binarized QR code |
808 | */ |
809 | CV_WRAP std::string detectAndDecodeCurved(InputArray img, OutputArray points=noArray(), |
810 | OutputArray straight_qrcode = noArray()); |
811 | }; |
812 | |
813 | class CV_EXPORTS_W_SIMPLE QRCodeDetectorAruco : public GraphicalCodeDetector { |
814 | public: |
815 | CV_WRAP QRCodeDetectorAruco(); |
816 | |
817 | struct CV_EXPORTS_W_SIMPLE Params { |
818 | CV_WRAP Params(); |
819 | |
820 | /** @brief The minimum allowed pixel size of a QR module in the smallest image in the image pyramid, default 4.f */ |
821 | CV_PROP_RW float minModuleSizeInPyramid; |
822 | |
823 | /** @brief The maximum allowed relative rotation for finder patterns in the same QR code, default pi/12 */ |
824 | CV_PROP_RW float maxRotation; |
825 | |
826 | /** @brief The maximum allowed relative mismatch in module sizes for finder patterns in the same QR code, default 1.75f */ |
827 | CV_PROP_RW float maxModuleSizeMismatch; |
828 | |
829 | /** @brief The maximum allowed module relative mismatch for timing pattern module, default 2.f |
830 | * |
831 | * If relative mismatch of timing pattern module more this value, penalty points will be added. |
832 | * If a lot of penalty points are added, QR code will be rejected. */ |
833 | CV_PROP_RW float maxTimingPatternMismatch; |
834 | |
835 | /** @brief The maximum allowed percentage of penalty points out of total pins in timing pattern, default 0.4f */ |
836 | CV_PROP_RW float maxPenalties; |
837 | |
838 | /** @brief The maximum allowed relative color mismatch in the timing pattern, default 0.2f*/ |
839 | CV_PROP_RW float maxColorsMismatch; |
840 | |
841 | /** @brief The algorithm find QR codes with almost minimum timing pattern score and minimum size, default 0.9f |
842 | * |
843 | * The QR code with the minimum "timing pattern score" and minimum "size" is selected as the best QR code. |
844 | * If for the current QR code "timing pattern score" * scaleTimingPatternScore < "previous timing pattern score" and "size" < "previous size", then |
845 | * current QR code set as the best QR code. */ |
846 | CV_PROP_RW float scaleTimingPatternScore; |
847 | }; |
848 | |
849 | /** @brief QR code detector constructor for Aruco-based algorithm. See cv::QRCodeDetectorAruco::Params */ |
850 | CV_WRAP explicit QRCodeDetectorAruco(const QRCodeDetectorAruco::Params& params); |
851 | |
852 | /** @brief Detector parameters getter. See cv::QRCodeDetectorAruco::Params */ |
853 | CV_WRAP const QRCodeDetectorAruco::Params& getDetectorParameters() const; |
854 | |
855 | /** @brief Detector parameters setter. See cv::QRCodeDetectorAruco::Params */ |
856 | CV_WRAP QRCodeDetectorAruco& setDetectorParameters(const QRCodeDetectorAruco::Params& params); |
857 | |
858 | /** @brief Aruco detector parameters are used to search for the finder patterns. */ |
859 | CV_WRAP const aruco::DetectorParameters& getArucoParameters() const; |
860 | |
861 | /** @brief Aruco detector parameters are used to search for the finder patterns. */ |
862 | CV_WRAP void setArucoParameters(const aruco::DetectorParameters& params); |
863 | }; |
864 | |
865 | //! @} |
866 | } |
867 | |
868 | #include "opencv2/objdetect/detection_based_tracker.hpp" |
869 | #include "opencv2/objdetect/face.hpp" |
870 | #include "opencv2/objdetect/charuco_detector.hpp" |
871 | #include "opencv2/objdetect/barcode.hpp" |
872 | |
873 | #endif |
874 |
Definitions
- SimilarRects
- SimilarRects
- operator()
- DefaultDeleter
- BaseCascadeClassifier
- MaskGenerator
- ~MaskGenerator
- initializeMask
- CascadeClassifier
- DetectionROI
- HOGDescriptor
- HistogramNormType
- DescriptorStorageFormat
- HOGDescriptor
- HOGDescriptor
- HOGDescriptor
- HOGDescriptor
- ~HOGDescriptor
- QRCodeEncoder
- EncodeMode
- CorrectionLevel
- ECIEncodings
- Params
- QRCodeDetector
- QRCodeDetectorAruco
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more