Skip to content

Commit 20c11d3

Browse files
committed
Update HOGDescriptor documentation
1 parent 0624411 commit 20c11d3

File tree

1 file changed

+212
-15
lines changed

1 file changed

+212
-15
lines changed

modules/objdetect/include/opencv2/objdetect.hpp

Lines changed: 212 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,54 @@ struct DetectionROI
352352
std::vector<double> confidences;
353353
};
354354

355-
/**@example peopledetect.cpp
355+
/**@brief Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector.
356+
357+
the HOG descriptor algorithm introduced by Navneet Dalal and Bill Triggs @cite Dalal2005 .
358+
359+
useful links:
360+
361+
https://hal.inria.fr/inria-00548512/document/
362+
363+
https://en.wikipedia.org/wiki/Histogram_of_oriented_gradients
364+
365+
https://software.intel.com/en-us/ipp-dev-reference-histogram-of-oriented-gradients-hog-descriptor
366+
367+
http://www.learnopencv.com/histogram-of-oriented-gradients
368+
369+
http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial
370+
356371
*/
357372
struct CV_EXPORTS_W HOGDescriptor
358373
{
359374
public:
360-
enum { L2Hys = 0
375+
enum { L2Hys = 0 //!< Default histogramNormType
361376
};
362-
enum { DEFAULT_NLEVELS = 64
377+
enum { DEFAULT_NLEVELS = 64 //!< Default nlevels value.
363378
};
379+
/**@brief Creates the HOG descriptor and detector with default params.
364380
381+
aqual to HOGDescriptor(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9, 1 )
382+
*/
365383
CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8),
366384
cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1),
367385
histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true),
368386
free_coef(-1.f), nlevels(HOGDescriptor::DEFAULT_NLEVELS), signedGradient(false)
369387
{}
370388

389+
/** @overload
390+
@param _winSize sets winSize with given value.
391+
@param _blockSize sets blockSize with given value.
392+
@param _blockStride sets blockStride with given value.
393+
@param _cellSize sets cellSize with given value.
394+
@param _nbins sets nbins with given value.
395+
@param _derivAperture sets derivAperture with given value.
396+
@param _winSigma sets winSigma with given value.
397+
@param _histogramNormType sets histogramNormType with given value.
398+
@param _L2HysThreshold sets L2HysThreshold with given value.
399+
@param _gammaCorrection sets gammaCorrection with given value.
400+
@param _nlevels sets nlevels with given value.
401+
@param _signedGradient sets signedGradient with given value.
402+
*/
371403
CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride,
372404
Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1,
373405
int _histogramNormType=HOGDescriptor::L2Hys,
@@ -379,97 +411,262 @@ struct CV_EXPORTS_W HOGDescriptor
379411
gammaCorrection(_gammaCorrection), free_coef(-1.f), nlevels(_nlevels), signedGradient(_signedGradient)
380412
{}
381413

414+
/** @overload
415+
@param filename the file name containing HOGDescriptor properties and coefficients of the trained classifier
416+
*/
382417
CV_WRAP HOGDescriptor(const String& filename)
383418
{
384419
load(filename);
385420
}
386421

422+
/** @overload
423+
@param d the HOGDescriptor which cloned to create a new one.
424+
*/
387425
HOGDescriptor(const HOGDescriptor& d)
388426
{
389427
d.copyTo(*this);
390428
}
391429

430+
/**@brief Default destructor.
431+
*/
392432
virtual ~HOGDescriptor() {}
393433

434+
/**@brief Returns the number of coefficients required for the classification.
435+
*/
394436
CV_WRAP size_t getDescriptorSize() const;
437+
438+
/** @brief Checks if detector size equal to descriptor size.
439+
*/
395440
CV_WRAP bool checkDetectorSize() const;
441+
442+
/** @brief Returns winSigma value
443+
*/
396444
CV_WRAP double getWinSigma() const;
397445

446+
/**@example peopledetect.cpp
447+
*/
448+
/**@brief Sets coefficients for the linear SVM classifier.
449+
@param _svmdetector coefficients for the linear SVM classifier.
450+
*/
398451
CV_WRAP virtual void setSVMDetector(InputArray _svmdetector);
399452

453+
/** @brief Reads HOGDescriptor parameters from a file node.
454+
@param fn File node
455+
*/
400456
virtual bool read(FileNode& fn);
457+
458+
/** @brief Stores HOGDescriptor parameters in a file storage.
459+
@param fs File storage
460+
@param objname Object name
461+
*/
401462
virtual void write(FileStorage& fs, const String& objname) const;
402463

464+
/** @brief loads coefficients for the linear SVM classifier from a file
465+
@param filename Name of the file to read.
466+
@param objname The optional name of the node to read (if empty, the first top-level node will be used).
467+
*/
403468
CV_WRAP virtual bool load(const String& filename, const String& objname = String());
469+
470+
/** @brief saves coefficients for the linear SVM classifier to a file
471+
@param filename File name
472+
@param objname Object name
473+
*/
404474
CV_WRAP virtual void save(const String& filename, const String& objname = String()) const;
475+
476+
/** @brief clones the HOGDescriptor
477+
@param c cloned HOGDescriptor
478+
*/
405479
virtual void copyTo(HOGDescriptor& c) const;
406480

481+
/**@example train_HOG.cpp
482+
*/
483+
/** @brief Computes HOG descriptors of given image.
484+
@param img Matrix of the type CV_8U containing an image where HOG features will be calculated.
485+
@param descriptors Matrix of the type CV_32F
486+
@param winStride Window stride. It must be a multiple of block stride.
487+
@param padding Padding
488+
@param locations Vector of Point
489+
*/
407490
CV_WRAP virtual void compute(InputArray img,
408491
CV_OUT std::vector<float>& descriptors,
409492
Size winStride = Size(), Size padding = Size(),
410493
const std::vector<Point>& locations = std::vector<Point>()) const;
411494

412-
//! with found weights output
495+
/** @brief Performs object detection without a multi-scale window.
496+
@param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
497+
@param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries.
498+
@param weights Vector that will contain confidence values for each detected object.
499+
@param hitThreshold Threshold for the distance between features and SVM classifying plane.
500+
Usually it is 0 and should be specfied in the detector coefficients (as the last free coefficient).
501+
But if the free coefficient is omitted (which is allowed), you can specify it manually here.
502+
@param winStride Window stride. It must be a multiple of block stride.
503+
@param padding Padding
504+
@param searchLocations Vector of Point includes set of requrested locations to be evaluated.
505+
*/
413506
CV_WRAP virtual void detect(const Mat& img, CV_OUT std::vector<Point>& foundLocations,
414507
CV_OUT std::vector<double>& weights,
415508
double hitThreshold = 0, Size winStride = Size(),
416509
Size padding = Size(),
417510
const std::vector<Point>& searchLocations = std::vector<Point>()) const;
418-
//! without found weights output
511+
512+
/** @brief Performs object detection without a multi-scale window.
513+
@param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
514+
@param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries.
515+
@param hitThreshold Threshold for the distance between features and SVM classifying plane.
516+
Usually it is 0 and should be specfied in the detector coefficients (as the last free coefficient).
517+
But if the free coefficient is omitted (which is allowed), you can specify it manually here.
518+
@param winStride Window stride. It must be a multiple of block stride.
519+
@param padding Padding
520+
@param searchLocations Vector of Point includes locations to search.
521+
*/
419522
virtual void detect(const Mat& img, CV_OUT std::vector<Point>& foundLocations,
420523
double hitThreshold = 0, Size winStride = Size(),
421524
Size padding = Size(),
422525
const std::vector<Point>& searchLocations=std::vector<Point>()) const;
423526

424-
//! with result weights output
527+
/** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list
528+
of rectangles.
529+
@param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
530+
@param foundLocations Vector of rectangles where each rectangle contains the detected object.
531+
@param foundWeights Vector that will contain confidence values for each detected object.
532+
@param hitThreshold Threshold for the distance between features and SVM classifying plane.
533+
Usually it is 0 and should be specfied in the detector coefficients (as the last free coefficient).
534+
But if the free coefficient is omitted (which is allowed), you can specify it manually here.
535+
@param winStride Window stride. It must be a multiple of block stride.
536+
@param padding Padding
537+
@param scale Coefficient of the detection window increase.
538+
@param finalThreshold Final threshold
539+
@param useMeanshiftGrouping indicates grouping algorithm
540+
*/
425541
CV_WRAP virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
426542
CV_OUT std::vector<double>& foundWeights, double hitThreshold = 0,
427543
Size winStride = Size(), Size padding = Size(), double scale = 1.05,
428544
double finalThreshold = 2.0,bool useMeanshiftGrouping = false) const;
429-
//! without found weights output
545+
546+
/** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list
547+
of rectangles.
548+
@param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
549+
@param foundLocations Vector of rectangles where each rectangle contains the detected object.
550+
@param hitThreshold Threshold for the distance between features and SVM classifying plane.
551+
Usually it is 0 and should be specfied in the detector coefficients (as the last free coefficient).
552+
But if the free coefficient is omitted (which is allowed), you can specify it manually here.
553+
@param winStride Window stride. It must be a multiple of block stride.
554+
@param padding Padding
555+
@param scale Coefficient of the detection window increase.
556+
@param finalThreshold Final threshold
557+
@param useMeanshiftGrouping indicates grouping algorithm
558+
*/
430559
virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
431560
double hitThreshold = 0, Size winStride = Size(),
432561
Size padding = Size(), double scale = 1.05,
433562
double finalThreshold = 2.0, bool useMeanshiftGrouping = false) const;
434563

564+
/** @brief Computes gradients and quantized gradient orientations.
565+
@param img Matrix contains the image to be computed
566+
@param grad Matrix of type CV_32FC2 contains computed gradients
567+
@param angleOfs Matrix of type CV_8UC2 contains quantized gradient orientations
568+
@param paddingTL Padding from top-left
569+
@param paddingBR Padding from bottom-right
570+
*/
435571
CV_WRAP virtual void computeGradient(const Mat& img, CV_OUT Mat& grad, CV_OUT Mat& angleOfs,
436572
Size paddingTL = Size(), Size paddingBR = Size()) const;
437573

574+
/** @brief Returns coefficients of the classifier trained for people detection (for 64x128 windows).
575+
*/
438576
CV_WRAP static std::vector<float> getDefaultPeopleDetector();
577+
578+
/**@example hog.cpp
579+
*/
580+
/** @brief Returns coefficients of the classifier trained for people detection (for 48x96 windows).
581+
*/
439582
CV_WRAP static std::vector<float> getDaimlerPeopleDetector();
440583

584+
//! Detection window size. Align to block size and block stride. Default value is Size(64,128).
441585
CV_PROP Size winSize;
586+
587+
//! Block size in pixels. Align to cell size. Default value is Size(16,16).
442588
CV_PROP Size blockSize;
589+
590+
//! Block stride. It must be a multiple of cell size. Default value is Size(8,8).
443591
CV_PROP Size blockStride;
592+
593+
//! Cell size. Default value is Size(8,8).
444594
CV_PROP Size cellSize;
595+
596+
//! Number of bins used in the calculation of histogram of gradients. Default value is 9.
445597
CV_PROP int nbins;
598+
599+
//! not documented
446600
CV_PROP int derivAperture;
601+
602+
//! Gaussian smoothing window parameter.
447603
CV_PROP double winSigma;
604+
605+
//! histogramNormType
448606
CV_PROP int histogramNormType;
607+
608+
//! L2-Hys normalization method shrinkage.
449609
CV_PROP double L2HysThreshold;
610+
611+
//! Flag to specify whether the gamma correction preprocessing is required or not.
450612
CV_PROP bool gammaCorrection;
613+
614+
//! coefficients for the linear SVM classifier.
451615
CV_PROP std::vector<float> svmDetector;
616+
617+
//! coefficients for the linear SVM classifier used when OpenCL is enabled
452618
UMat oclSvmDetector;
619+
620+
//! not documented
453621
float free_coef;
622+
623+
//! Maximum number of detection window increases. Default value is 64
454624
CV_PROP int nlevels;
455-
CV_PROP bool signedGradient;
456625

626+
//! Indicates signed gradient will be used or not
627+
CV_PROP bool signedGradient;
457628

458-
//! evaluate specified ROI and return confidence value for each location
629+
/** @brief evaluate specified ROI and return confidence value for each location
630+
@param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
631+
@param locations Vector of Point
632+
@param foundLocations Vector of Point where each Point is detected object's top-left point.
633+
@param confidences confidences
634+
@param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually
635+
it is 0 and should be specfied in the detector coefficients (as the last free coefficient). But if
636+
the free coefficient is omitted (which is allowed), you can specify it manually here
637+
@param winStride winStride
638+
@param padding padding
639+
*/
459640
virtual void detectROI(const cv::Mat& img, const std::vector<cv::Point> &locations,
460641
CV_OUT std::vector<cv::Point>& foundLocations, CV_OUT std::vector<double>& confidences,
461642
double hitThreshold = 0, cv::Size winStride = Size(),
462643
cv::Size padding = Size()) const;
463644

464-
//! evaluate specified ROI and return confidence value for each location in multiple scales
645+
/** @brief evaluate specified ROI and return confidence value for each location in multiple scales
646+
@param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
647+
@param foundLocations Vector of rectangles where each rectangle contains the detected object.
648+
@param locations Vector of DetectionROI
649+
@param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specfied
650+
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.
651+
@param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it.
652+
*/
465653
virtual void detectMultiScaleROI(const cv::Mat& img,
466-
CV_OUT std::vector<cv::Rect>& foundLocations,
467-
std::vector<DetectionROI>& locations,
468-
double hitThreshold = 0,
469-
int groupThreshold = 0) const;
654+
CV_OUT std::vector<cv::Rect>& foundLocations,
655+
std::vector<DetectionROI>& locations,
656+
double hitThreshold = 0,
657+
int groupThreshold = 0) const;
470658

471-
//! read/parse Dalal's alt model file
659+
/** @brief read/parse Dalal's alt model file
660+
@param modelfile Path of Dalal's alt model file.
661+
*/
472662
void readALTModel(String modelfile);
663+
664+
/** @brief Groups the object candidate rectangles.
665+
@param rectList Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.)
666+
@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.)
667+
@param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it.
668+
@param eps Relative difference between sides of the rectangles to merge them into a group.
669+
*/
473670
void groupRectangles(std::vector<cv::Rect>& rectList, std::vector<double>& weights, int groupThreshold, double eps) const;
474671
};
475672

0 commit comments

Comments
 (0)