OpenCV 4.5.3(日本語機械翻訳)
objdetect.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 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
109 typedef struct CvHaarClassifierCascade CvHaarClassifierCascade;
110
111 namespace cv
112{
113
116
118
121 class CV_EXPORTS SimilarRects
122{
123 public:
124 SimilarRects(double _eps) : eps(_eps) {}
125 inline bool operator()(const Rect& r1, const Rect& r2) const
126 {
127 double delta = eps * ((std::min)(r1.width, r2.width) + (std::min)(r1.height, r2.height)) * 0.5;
128 return std::abs(r1.x - r2.x) <= delta &&
129 std::abs(r1.y - r2.y) <= delta &&
130 std::abs(r1.x + r1.width - r2.x - r2.width) <= delta &&
131 std::abs(r1.y + r1.height - r2.y - r2.height) <= delta;
132 }
133 double eps;
134};
135
151 CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, int groupThreshold, double eps = 0.2);
153 CV_EXPORTS_W void groupRectangles(CV_IN_OUT std::vector<Rect>& rectList, CV_OUT std::vector<int>& weights,
154 int groupThreshold, double eps = 0.2);
156 CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, int groupThreshold,
157 double eps, std::vector<int>* weights, std::vector<double>* levelWeights );
159 CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, std::vector<int>& rejectLevels,
160 std::vector<double>& levelWeights, int groupThreshold, double eps = 0.2);
162 CV_EXPORTS void groupRectangles_meanshift(std::vector<Rect>& rectList, std::vector<double>& foundWeights,
163 std::vector<double>& foundScales,
164 double detectThreshold = 0.0, Size winDetSize = Size(64, 128));
165
166 template<> struct DefaultDeleter<CvHaarClassifierCascade>{ CV_EXPORTS void operator ()(CvHaarClassifierCascade* obj) const; };
167
168 enum { CASCADE_DO_CANNY_PRUNING = 1,
169 CASCADE_SCALE_IMAGE = 2,
170 CASCADE_FIND_BIGGEST_OBJECT = 4,
171 CASCADE_DO_ROUGH_SEARCH = 8
172 };
173
174 class CV_EXPORTS_W BaseCascadeClassifier : public Algorithm
175{
176 public:
177 virtual ~BaseCascadeClassifier();
178 virtual bool empty() const CV_OVERRIDE = 0;
179 virtual bool load( const String& filename ) = 0;
180 virtual void detectMultiScale( InputArray image,
181 CV_OUT std::vector<Rect>& objects,
182 double scaleFactor,
183 int minNeighbors, int flags,
184 Size minSize, Size maxSize ) = 0;
185
186 virtual void detectMultiScale( InputArray image,
187 CV_OUT std::vector<Rect>& objects,
188 CV_OUT std::vector<int>& numDetections,
189 double scaleFactor,
190 int minNeighbors, int flags,
191 Size minSize, Size maxSize ) = 0;
192
193 virtual void detectMultiScale( InputArray image,
194 CV_OUT std::vector<Rect>& objects,
195 CV_OUT std::vector<int>& rejectLevels,
196 CV_OUT std::vector<double>& levelWeights,
197 double scaleFactor,
198 int minNeighbors, int flags,
199 Size minSize, Size maxSize,
200 bool outputRejectLevels ) = 0;
201
202 virtual bool isOldFormatCascade() const = 0;
203 virtual Size getOriginalWindowSize() const = 0;
204 virtual int getFeatureType() const = 0;
205 virtual void* getOldCascade() = 0;
206
207 class CV_EXPORTS MaskGenerator
208 {
209 public:
210 virtual ~MaskGenerator() {}
211 virtual Mat generateMask(const Mat& src)=0;
212 virtual void initializeMask(const Mat& /*src*/) { }
213 };
214 virtual void setMaskGenerator(const Ptr<MaskGenerator>& maskGenerator) = 0;
215 virtual Ptr<MaskGenerator> getMaskGenerator() = 0;
216};
217
224 class CV_EXPORTS_W CascadeClassifier
225{
226 public:
227 CV_WRAP CascadeClassifier();
232 CV_WRAP CascadeClassifier(const String& filename);
236 CV_WRAP bool empty() const;
243 CV_WRAP bool load( const String& filename );
248 CV_WRAP bool read( const FileNode& node );
249
270 CV_WRAP void detectMultiScale( InputArray image,
271 CV_OUT std::vector<Rect>& objects,
272 double scaleFactor = 1.1,
273 int minNeighbors = 3, int flags = 0,
274 Size minSize = Size(),
275 Size maxSize = Size() );
276
292 CV_WRAP_AS(detectMultiScale2) void detectMultiScale( InputArray image,
293 CV_OUT std::vector<Rect>& objects,
294 CV_OUT std::vector<int>& numDetections,
295 double scaleFactor=1.1,
296 int minNeighbors=3, int flags=0,
297 Size minSize=Size(),
298 Size maxSize=Size() );
299
317 CV_WRAP_AS(detectMultiScale3) void detectMultiScale( InputArray image,
318 CV_OUT std::vector<Rect>& objects,
319 CV_OUT std::vector<int>& rejectLevels,
320 CV_OUT std::vector<double>& levelWeights,
321 double scaleFactor = 1.1,
322 int minNeighbors = 3, int flags = 0,
323 Size minSize = Size(),
324 Size maxSize = Size(),
325 bool outputRejectLevels = false );
326
327 CV_WRAP bool isOldFormatCascade() const;
328 CV_WRAP Size getOriginalWindowSize() const;
329 CV_WRAP int getFeatureType() const;
330 void* getOldCascade();
331
332 CV_WRAP static bool convert(const String& oldcascade, const String& newcascade);
333
334 void setMaskGenerator(const Ptr<BaseCascadeClassifier::MaskGenerator>& maskGenerator);
336
338};
339
340CV_EXPORTS Ptr<BaseCascadeClassifier::MaskGenerator> createFaceDetectionMaskGenerator();
341
343
346{
348 double scale;
350 std::vector<cv::Point> locations;
352 std::vector<double> confidences;
353};
354
372 struct CV_EXPORTS_W HOGDescriptor
373{
374 public:
375 enum HistogramNormType { L2Hys = 0
376 };
377 enum { DEFAULT_NLEVELS = 64
378 };
379 enum DescriptorStorageFormat { DESCR_FORMAT_COL_BY_COL, DESCR_FORMAT_ROW_BY_ROW };
380
385 CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8),
386 cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1),
387 histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true),
388 free_coef(-1.f), nlevels(HOGDescriptor::DEFAULT_NLEVELS), signedGradient(false)
389 {}
390
405 CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride,
406 Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1,
408 double _L2HysThreshold=0.2, bool _gammaCorrection=false,
409 int _nlevels=HOGDescriptor::DEFAULT_NLEVELS, bool _signedGradient=false)
410 : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize),
411 nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma),
412 histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold),
413 gammaCorrection(_gammaCorrection), free_coef(-1.f), nlevels(_nlevels), signedGradient(_signedGradient)
414 {}
415
419 CV_WRAP HOGDescriptor(const String& filename)
420 {
421 load(filename);
422 }
423
428 {
429 d.copyTo(*this);
430 }
431
434 virtual ~HOGDescriptor() {}
435
438 CV_WRAP size_t getDescriptorSize() const;
439
442 CV_WRAP bool checkDetectorSize() const;
443
446 CV_WRAP double getWinSigma() const;
447
453 CV_WRAP virtual void setSVMDetector(InputArray svmdetector);
454
458 virtual bool read(FileNode& fn);
459
464 virtual void write(FileStorage& fs, const String& objname) const;
465
470 CV_WRAP virtual bool load(const String& filename, const String& objname = String());
471
476 CV_WRAP virtual void save(const String& filename, const String& objname = String()) const;
477
481 virtual void copyTo(HOGDescriptor& c) const;
482
492 CV_WRAP virtual void compute(InputArray img,
493 CV_OUT std::vector<float>& descriptors,
494 Size winStride = Size(), Size padding = Size(),
495 const std::vector<Point>& locations = std::vector<Point>()) const;
496
508 CV_WRAP virtual void detect(InputArray img, CV_OUT std::vector<Point>& foundLocations,
509 CV_OUT std::vector<double>& weights,
510 double hitThreshold = 0, Size winStride = Size(),
511 Size padding = Size(),
512 const std::vector<Point>& searchLocations = std::vector<Point>()) const;
513
524 virtual void detect(InputArray img, CV_OUT std::vector<Point>& foundLocations,
525 double hitThreshold = 0, Size winStride = Size(),
526 Size padding = Size(),
527 const std::vector<Point>& searchLocations=std::vector<Point>()) const;
528
543 CV_WRAP virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
544 CV_OUT std::vector<double>& foundWeights, double hitThreshold = 0,
545 Size winStride = Size(), Size padding = Size(), double scale = 1.05,
546 double finalThreshold = 2.0,bool useMeanshiftGrouping = false) const;
547
561 virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
562 double hitThreshold = 0, Size winStride = Size(),
563 Size padding = Size(), double scale = 1.05,
564 double finalThreshold = 2.0, bool useMeanshiftGrouping = false) const;
565
573 CV_WRAP virtual void computeGradient(InputArray img, InputOutputArray grad, InputOutputArray angleOfs,
574 Size paddingTL = Size(), Size paddingBR = Size()) const;
575
578 CV_WRAP static std::vector<float> getDefaultPeopleDetector();
579
584 CV_WRAP static std::vector<float> getDaimlerPeopleDetector();
585
587 CV_PROP Size winSize;
588
590 CV_PROP Size blockSize;
591
593 CV_PROP Size blockStride;
594
596 CV_PROP Size cellSize;
597
599 CV_PROP int nbins;
600
602 CV_PROP int derivAperture;
603
605 CV_PROP double winSigma;
606
608 CV_PROP HOGDescriptor::HistogramNormType histogramNormType;
609
611 CV_PROP double L2HysThreshold;
612
614 CV_PROP bool gammaCorrection;
615
617 CV_PROP std::vector<float> svmDetector;
618
621
624
626 CV_PROP int nlevels;
627
629 CV_PROP bool signedGradient;
630
642 virtual void detectROI(InputArray img, const std::vector<cv::Point> &locations,
643 CV_OUT std::vector<cv::Point>& foundLocations, CV_OUT std::vector<double>& confidences,
644 double hitThreshold = 0, cv::Size winStride = Size(),
645 cv::Size padding = Size()) const;
646
655 virtual void detectMultiScaleROI(InputArray img,
656 CV_OUT std::vector<cv::Rect>& foundLocations,
657 std::vector<DetectionROI>& locations,
658 double hitThreshold = 0,
659 int groupThreshold = 0) const;
660
667 void groupRectangles(std::vector<cv::Rect>& rectList, std::vector<double>& weights, int groupThreshold, double eps) const;
668};
669
670 class CV_EXPORTS_W QRCodeDetector
671{
672 public:
673 CV_WRAP QRCodeDetector();
675
680 CV_WRAP void setEpsX(double epsX);
685 CV_WRAP void setEpsY(double epsY);
686
691 CV_WRAP bool detect(InputArray img, OutputArray points) const;
692
700 CV_WRAP std::string decode(InputArray img, InputArray points, OutputArray straight_qrcode = noArray());
701
709 CV_WRAP cv::String decodeCurved(InputArray img, InputArray points, OutputArray straight_qrcode = noArray());
710
717 CV_WRAP std::string detectAndDecode(InputArray img, OutputArray points=noArray(),
718 OutputArray straight_qrcode = noArray());
719
726 CV_WRAP std::string detectAndDecodeCurved(InputArray img, OutputArray points=noArray(),
727 OutputArray straight_qrcode = noArray());
728
733 CV_WRAP
734 bool detectMulti(InputArray img, OutputArray points) const;
735
742 CV_WRAP
744 InputArray img, InputArray points,
745 CV_OUT std::vector<std::string>& decoded_info,
746 OutputArrayOfArrays straight_qrcode = noArray()
747 ) const;
748
755 CV_WRAP
757 InputArray img, CV_OUT std::vector<std::string>& decoded_info,
758 OutputArray points = noArray(),
759 OutputArrayOfArrays straight_qrcode = noArray()
760 ) const;
761
762 protected:
763 struct Impl;
764 Ptr<Impl> p;
765};
766
768}
769
770 #include "opencv2/objdetect/detection_based_tracker.hpp"
771
772 #endif
Definition: mat.hpp:386
This type is very similar to InputArray except that it is used for input/output and output function p...
Definition: mat.hpp:295
This is a base class for all more or less complex algorithms in OpenCV
Definition: core.hpp:3091
Definition: objdetect.hpp:208
Definition: objdetect.hpp:175
virtual bool empty() const CV_OVERRIDE=0
Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read
Cascade classifier class for object detection.
Definition: objdetect.hpp:225
CV_WRAP_AS(detectMultiScale3) void detectMultiScale(InputArray image
CV_WRAP_AS(detectMultiScale2) void detectMultiScale(InputArray image
File Storage Node class.
Definition: persistence.hpp:482
XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or readi...
Definition: persistence.hpp:304
n-dimensional dense array class
Definition: mat.hpp:802
Definition: objdetect.hpp:671
CV_WRAP bool decodeMulti(InputArray img, InputArray points, CV_OUT std::vector< std::string > &decoded_info, OutputArrayOfArrays straight_qrcode=noArray()) const
Decodes QR codes in image once it's found by the detect() method.
CV_WRAP bool detectMulti(InputArray img, OutputArray points) const
Detects QR codes in image and returns the vector of the quadrangles containing the codes.
CV_WRAP bool detectAndDecodeMulti(InputArray img, CV_OUT std::vector< std::string > &decoded_info, OutputArray points=noArray(), OutputArrayOfArrays straight_qrcode=noArray()) const
Both detects and decodes QR codes
Template class for 2D rectangles
Definition: core/types.hpp:421
_Tp x
x coordinate of the top-left corner
Definition: core/types.hpp:453
_Tp y
y coordinate of the top-left corner
Definition: core/types.hpp:454
_Tp width
width of the rectangle
Definition: core/types.hpp:455
_Tp height
height of the rectangle
Definition: core/types.hpp:456
Definition: objdetect.hpp:122
Template class for specifying the size of an image or rectangle.
Definition: core/types.hpp:316
Definition: mat.hpp:2402
CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst)
Calculates per-element minimum of two arrays or an array and a scalar.
softfloat abs(softfloat a)
Absolute value
Definition: softfloat.hpp:444
CV_EXPORTS_W void gammaCorrection(const Mat input, Mat &output, const float gamma)
Given an input bgr or grayscale image and constant gamma, apply power-law transformation,...
CV_EXPORTS void groupRectangles_meanshift(std::vector< Rect > &rectList, std::vector< double > &foundWeights, std::vector< double > &foundScales, double detectThreshold=0.0, Size winDetSize=Size(64, 128))
CV_EXPORTS void groupRectangles(std::vector< Rect > &rectList, int groupThreshold, double eps=0.2)
Groups the object candidate rectangles.
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvstd_wrapper.hpp:32
struct for detection region of interest (ROI)
Definition: objdetect.hpp:346
std::vector< double > confidences
vector that will contain confidence values for each location
Definition: objdetect.hpp:352
double scale
scale(size) of the bounding box
Definition: objdetect.hpp:348
std::vector< cv::Point > locations
set of requested locations to be evaluated
Definition: objdetect.hpp:350
Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector.
Definition: objdetect.hpp:373
@ DEFAULT_NLEVELS
Default nlevels value.
Definition: objdetect.hpp:377
virtual bool read(FileNode &fn)
Reads HOGDescriptor parameters from a cv::FileNode.
virtual void detectMultiScale(InputArray img, CV_OUT std::vector< Rect > &foundLocations, double hitThreshold=0, Size winStride=Size(), Size padding=Size(), double scale=1.05, double finalThreshold=2.0, bool useMeanshiftGrouping=false) const
Detects objects of different sizes in the input image. The detected objects are returned as a list of...
virtual void write(FileStorage &fs, const String &objname) const
Stores HOGDescriptor parameters in a cv::FileStorage.
UMat oclSvmDetector
coefficients for the linear SVM classifier used when OpenCL is enabled
Definition: objdetect.hpp:620
float free_coef
not documented
Definition: objdetect.hpp:623
virtual ~HOGDescriptor()
Default destructor.
Definition: objdetect.hpp:434
virtual void detect(InputArray img, CV_OUT std::vector< Point > &foundLocations, double hitThreshold=0, Size winStride=Size(), Size padding=Size(), const std::vector< Point > &searchLocations=std::vector< Point >()) const
Performs object detection without a multi-scale window.
HistogramNormType
Definition: objdetect.hpp:375
@ L2Hys
Default histogramNormType
Definition: objdetect.hpp:375
virtual void copyTo(HOGDescriptor &c) const
clones the HOGDescriptor
HOGDescriptor(const HOGDescriptor &d)
Definition: objdetect.hpp:427
virtual void detectROI(InputArray img, const std::vector< cv::Point > &locations, CV_OUT std::vector< cv::Point > &foundLocations, CV_OUT std::vector< double > &confidences, double hitThreshold=0, cv::Size winStride=Size(), cv::Size padding=Size()) const
evaluate specified ROI and return confidence value for each location
void groupRectangles(std::vector< cv::Rect > &rectList, std::vector< double > &weights, int groupThreshold, double eps) const
Groups the object candidate rectangles.
virtual void detectMultiScaleROI(InputArray img, CV_OUT std::vector< cv::Rect > &foundLocations, std::vector< DetectionROI > &locations, double hitThreshold=0, int groupThreshold=0) const
evaluate specified ROI and return confidence value for each location in multiple scales
Definition: cvstd_wrapper.hpp:74