OpenCV  5.0.0alpha
Open Source Computer Vision
Loading...
Searching...
No Matches

Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector. More...

#include <opencv2/xobjdetect.hpp>

Collaboration diagram for cv::HOGDescriptor:

Public Types

enum  { DEFAULT_NLEVELS = 64 }
 
enum  DescriptorStorageFormat {
  DESCR_FORMAT_COL_BY_COL ,
  DESCR_FORMAT_ROW_BY_ROW
}
 
enum  HistogramNormType { L2Hys = 0 }
 

Public Member Functions

 HOGDescriptor (const HOGDescriptor &d)
 
 HOGDescriptor (const String &filename)
 
 HOGDescriptor (Size _winSize=Size(64, 128), Size _blockSize=Size(16, 16), Size _blockStride=Size(8, 8), Size _cellSize=Size(8, 8), int _nbins=9, int _derivAperture=1, double _winSigma=-1, HOGDescriptor::HistogramNormType _histogramNormType=HOGDescriptor::L2Hys, double _L2HysThreshold=0.2, bool _gammaCorrection=true, int _nlevels=HOGDescriptor::DEFAULT_NLEVELS, bool _signedGradient=false)
 Creates the HOG descriptor and detector with default parameters.
 
virtual ~HOGDescriptor ()
 Default destructor.
 
bool checkDetectorSize () const
 Checks if detector size equal to descriptor size.
 
virtual void compute (InputArray img, std::vector< float > &descriptors, Size winStride=Size(), Size padding=Size(), const std::vector< Point > &locations=std::vector< Point >()) const
 Computes HOG descriptors of given image.
 
virtual void computeGradient (InputArray img, InputOutputArray grad, InputOutputArray angleOfs, Size paddingTL=Size(), Size paddingBR=Size()) const
 Computes gradients and quantized gradient orientations.
 
virtual void copyTo (HOGDescriptor &c) const
 clones the HOGDescriptor
 
virtual void detect (InputArray img, 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.
 
virtual void detect (InputArray img, std::vector< Point > &foundLocations, std::vector< double > &weights, 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.
 
virtual void detectMultiScale (InputArray img, std::vector< Rect > &foundLocations, double hitThreshold=0, Size winStride=Size(), Size padding=Size(), double scale=1.05, double groupThreshold=2.0, bool useMeanshiftGrouping=false) const
 Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
 
virtual void detectMultiScale (InputArray img, std::vector< Rect > &foundLocations, std::vector< double > &foundWeights, double hitThreshold=0, Size winStride=Size(), Size padding=Size(), double scale=1.05, double groupThreshold=2.0, bool useMeanshiftGrouping=false) const
 Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
 
virtual void detectMultiScaleROI (InputArray img, 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
 
virtual void detectROI (InputArray img, const std::vector< cv::Point > &locations, std::vector< cv::Point > &foundLocations, 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
 
size_t getDescriptorSize () const
 Returns the number of coefficients required for the classification.
 
double getWinSigma () const
 Returns winSigma value.
 
void groupRectangles (std::vector< cv::Rect > &rectList, std::vector< double > &weights, int groupThreshold, double eps) const
 Groups the object candidate rectangles.
 
virtual bool load (const String &filename, const String &objname=String())
 loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file
 
virtual bool read (FileNode &fn)
 Reads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file node.
 
virtual void save (const String &filename, const String &objname=String()) const
 saves HOGDescriptor parameters and coefficients for the linear SVM classifier to a file
 
virtual void setSVMDetector (InputArray svmdetector)
 Sets coefficients for the linear SVM classifier.
 
virtual void write (FileStorage &fs, const String &objname) const
 Stores HOGDescriptor parameters and coefficients for the linear SVM classifier in a file storage.
 

Static Public Member Functions

static std::vector< float > getDaimlerPeopleDetector ()
 Returns coefficients of the classifier trained for people detection (for 48x96 windows).
 
static std::vector< float > getDefaultPeopleDetector ()
 Returns coefficients of the classifier trained for people detection (for 64x128 windows).
 

Public Attributes

Size blockSize
 Block size in pixels. Align to cell size. Default value is Size(16,16).
 
Size blockStride
 Block stride. It must be a multiple of cell size. Default value is Size(8,8).
 
Size cellSize
 Cell size. Default value is Size(8,8).
 
int derivAperture
 not documented
 
float free_coef
 not documented
 
bool gammaCorrection
 Flag to specify whether the gamma correction preprocessing is required or not.
 
HOGDescriptor::HistogramNormType histogramNormType
 histogramNormType
 
double L2HysThreshold
 L2-Hys normalization method shrinkage.
 
int nbins
 Number of bins used in the calculation of histogram of gradients. Default value is 9.
 
int nlevels
 Maximum number of detection window increases. Default value is 64.
 
UMat oclSvmDetector
 coefficients for the linear SVM classifier used when OpenCL is enabled
 
bool signedGradient
 Indicates signed gradient will be used or not.
 
std::vector< float > svmDetector
 coefficients for the linear SVM classifier.
 
double winSigma
 Gaussian smoothing window parameter.
 
Size winSize
 Detection window size. Align to block size and block stride. Default value is Size(64,128).
 

Detailed Description

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
DEFAULT_NLEVELS 

Default nlevels value.

◆ DescriptorStorageFormat

Enumerator
DESCR_FORMAT_COL_BY_COL 
DESCR_FORMAT_ROW_BY_ROW 

◆ HistogramNormType

Enumerator
L2Hys 

Default histogramNormType.

Constructor & Destructor Documentation

◆ HOGDescriptor() [1/3]

cv::HOGDescriptor::HOGDescriptor ( Size _winSize = Size(64, 128),
Size _blockSize = Size(16, 16),
Size _blockStride = Size(8, 8),
Size _cellSize = Size(8, 8),
int _nbins = 9,
int _derivAperture = 1,
double _winSigma = -1,
HOGDescriptor::HistogramNormType _histogramNormType = HOGDescriptor::L2Hys,
double _L2HysThreshold = 0.2,
bool _gammaCorrection = true,
int _nlevels = HOGDescriptor::DEFAULT_NLEVELS,
bool _signedGradient = false )
inline
Python:
cv.HOGDescriptor([, _winSize[, _blockSize[, _blockStride[, _cellSize[, _nbins[, _derivAperture[, _winSigma[, _histogramNormType[, _L2HysThreshold[, _gammaCorrection[, _nlevels[, _signedGradient]]]]]]]]]]]]) -> <HOGDescriptor object>
cv.HOGDescriptor(filename) -> <HOGDescriptor object>

Creates the HOG descriptor and detector with default parameters.

Parameters
_winSizesets winSize with given value.
_blockSizesets blockSize with given value.
_blockStridesets blockStride with given value.
_cellSizesets cellSize with given value.
_nbinssets nbins with given value.
_derivAperturesets derivAperture with given value.
_winSigmasets winSigma with given value.
_histogramNormTypesets histogramNormType with given value.
_L2HysThresholdsets L2HysThreshold with given value.
_gammaCorrectionsets gammaCorrection with given value.
_nlevelssets nlevels with given value.
_signedGradientsets signedGradient with given value.

◆ HOGDescriptor() [2/3]

cv::HOGDescriptor::HOGDescriptor ( const String & filename)
inline
Python:
cv.HOGDescriptor([, _winSize[, _blockSize[, _blockStride[, _cellSize[, _nbins[, _derivAperture[, _winSigma[, _histogramNormType[, _L2HysThreshold[, _gammaCorrection[, _nlevels[, _signedGradient]]]]]]]]]]]]) -> <HOGDescriptor object>
cv.HOGDescriptor(filename) -> <HOGDescriptor object>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Creates the HOG descriptor and detector and loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file.

Parameters
filenameThe file name containing HOGDescriptor properties and coefficients for the linear SVM classifier.

◆ HOGDescriptor() [3/3]

cv::HOGDescriptor::HOGDescriptor ( const HOGDescriptor & d)
inline
Python:
cv.HOGDescriptor([, _winSize[, _blockSize[, _blockStride[, _cellSize[, _nbins[, _derivAperture[, _winSigma[, _histogramNormType[, _L2HysThreshold[, _gammaCorrection[, _nlevels[, _signedGradient]]]]]]]]]]]]) -> <HOGDescriptor object>
cv.HOGDescriptor(filename) -> <HOGDescriptor object>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
dthe HOGDescriptor which cloned to create a new one.
Here is the call graph for this function:

◆ ~HOGDescriptor()

virtual cv::HOGDescriptor::~HOGDescriptor ( )
inlinevirtual

Default destructor.

Member Function Documentation

◆ checkDetectorSize()

bool cv::HOGDescriptor::checkDetectorSize ( ) const
Python:
cv.HOGDescriptor.checkDetectorSize() -> retval

Checks if detector size equal to descriptor size.

◆ compute()

virtual void cv::HOGDescriptor::compute ( InputArray img,
std::vector< float > & descriptors,
Size winStride = Size(),
Size padding = Size(),
const std::vector< Point > & locations = std::vector< Point >() ) const
virtual
Python:
cv.HOGDescriptor.compute(img[, winStride[, padding[, locations]]]) -> descriptors

Computes HOG descriptors of given image.

Parameters
imgMatrix of the type CV_8U containing an image where HOG features will be calculated.
descriptorsMatrix of the type CV_32F
winStrideWindow stride. It must be a multiple of block stride.
paddingPadding
locationsVector of Point

◆ computeGradient()

virtual void cv::HOGDescriptor::computeGradient ( InputArray img,
InputOutputArray grad,
InputOutputArray angleOfs,
Size paddingTL = Size(),
Size paddingBR = Size() ) const
virtual
Python:
cv.HOGDescriptor.computeGradient(img, grad, angleOfs[, paddingTL[, paddingBR]]) -> grad, angleOfs

Computes gradients and quantized gradient orientations.

Parameters
imgMatrix contains the image to be computed
gradMatrix of type CV_32FC2 contains computed gradients
angleOfsMatrix of type CV_8UC2 contains quantized gradient orientations
paddingTLPadding from top-left
paddingBRPadding from bottom-right

◆ copyTo()

virtual void cv::HOGDescriptor::copyTo ( HOGDescriptor & c) const
virtual

clones the HOGDescriptor

Parameters
ccloned HOGDescriptor

◆ detect() [1/2]

virtual void cv::HOGDescriptor::detect ( InputArray img,
std::vector< Point > & foundLocations,
double hitThreshold = 0,
Size winStride = Size(),
Size padding = Size(),
const std::vector< Point > & searchLocations = std::vector< Point >() ) const
virtual
Python:
cv.HOGDescriptor.detect(img[, hitThreshold[, winStride[, padding[, searchLocations]]]]) -> foundLocations, weights

Performs object detection without a multi-scale window.

Parameters
imgMatrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
foundLocationsVector of point where each point contains left-top corner point of detected object boundaries.
hitThresholdThreshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified 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.
winStrideWindow stride. It must be a multiple of block stride.
paddingPadding
searchLocationsVector of Point includes locations to search.

◆ detect() [2/2]

virtual void cv::HOGDescriptor::detect ( InputArray img,
std::vector< Point > & foundLocations,
std::vector< double > & weights,
double hitThreshold = 0,
Size winStride = Size(),
Size padding = Size(),
const std::vector< Point > & searchLocations = std::vector< Point >() ) const
virtual
Python:
cv.HOGDescriptor.detect(img[, hitThreshold[, winStride[, padding[, searchLocations]]]]) -> foundLocations, weights

Performs object detection without a multi-scale window.

Parameters
imgMatrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
foundLocationsVector of point where each point contains left-top corner point of detected object boundaries.
weightsVector that will contain confidence values for each detected object.
hitThresholdThreshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified 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.
winStrideWindow stride. It must be a multiple of block stride.
paddingPadding
searchLocationsVector of Point includes set of requested locations to be evaluated.

◆ detectMultiScale() [1/2]

virtual void cv::HOGDescriptor::detectMultiScale ( InputArray img,
std::vector< Rect > & foundLocations,
double hitThreshold = 0,
Size winStride = Size(),
Size padding = Size(),
double scale = 1.05,
double groupThreshold = 2.0,
bool useMeanshiftGrouping = false ) const
virtual
Python:
cv.HOGDescriptor.detectMultiScale(img[, hitThreshold[, winStride[, padding[, scale[, groupThreshold[, useMeanshiftGrouping]]]]]]) -> foundLocations, foundWeights

Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.

Parameters
imgMatrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
foundLocationsVector of rectangles where each rectangle contains the detected object.
hitThresholdThreshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified 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.
winStrideWindow stride. It must be a multiple of block stride.
paddingPadding
scaleCoefficient of the detection window increase.
groupThresholdCoefficient to regulate the similarity threshold. When detected, some objects can be covered by many rectangles. 0 means not to perform grouping.
useMeanshiftGroupingindicates grouping algorithm

◆ detectMultiScale() [2/2]

virtual void cv::HOGDescriptor::detectMultiScale ( InputArray img,
std::vector< Rect > & foundLocations,
std::vector< double > & foundWeights,
double hitThreshold = 0,
Size winStride = Size(),
Size padding = Size(),
double scale = 1.05,
double groupThreshold = 2.0,
bool useMeanshiftGrouping = false ) const
virtual
Python:
cv.HOGDescriptor.detectMultiScale(img[, hitThreshold[, winStride[, padding[, scale[, groupThreshold[, useMeanshiftGrouping]]]]]]) -> foundLocations, foundWeights

Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.

Parameters
imgMatrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
foundLocationsVector of rectangles where each rectangle contains the detected object.
foundWeightsVector that will contain confidence values for each detected object.
hitThresholdThreshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified 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.
winStrideWindow stride. It must be a multiple of block stride.
paddingPadding
scaleCoefficient of the detection window increase.
groupThresholdCoefficient to regulate the similarity threshold. When detected, some objects can be covered by many rectangles. 0 means not to perform grouping.
useMeanshiftGroupingindicates grouping algorithm
Examples
samples/peopledetect.cpp.

◆ detectMultiScaleROI()

virtual void cv::HOGDescriptor::detectMultiScaleROI ( InputArray img,
std::vector< cv::Rect > & foundLocations,
std::vector< DetectionROI > & locations,
double hitThreshold = 0,
int groupThreshold = 0 ) const
virtual

evaluate specified ROI and return confidence value for each location in multiple scales

Parameters
imgMatrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
foundLocationsVector of rectangles where each rectangle contains the detected object.
locationsVector of DetectionROI
hitThresholdThreshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified 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.
groupThresholdMinimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it.

◆ detectROI()

virtual void cv::HOGDescriptor::detectROI ( InputArray img,
const std::vector< cv::Point > & locations,
std::vector< cv::Point > & foundLocations,
std::vector< double > & confidences,
double hitThreshold = 0,
cv::Size winStride = Size(),
cv::Size padding = Size() ) const
virtual

evaluate specified ROI and return confidence value for each location

Parameters
imgMatrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.
locationsVector of Point
foundLocationsVector of Point where each Point is detected object's top-left point.
confidencesconfidences
hitThresholdThreshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified 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
winStridewinStride
paddingpadding

◆ getDaimlerPeopleDetector()

static std::vector< float > cv::HOGDescriptor::getDaimlerPeopleDetector ( )
static
Python:
cv.HOGDescriptor.getDaimlerPeopleDetector() -> retval
cv.HOGDescriptor_getDaimlerPeopleDetector() -> retval

Returns coefficients of the classifier trained for people detection (for 48x96 windows).

◆ getDefaultPeopleDetector()

static std::vector< float > cv::HOGDescriptor::getDefaultPeopleDetector ( )
static
Python:
cv.HOGDescriptor.getDefaultPeopleDetector() -> retval
cv.HOGDescriptor_getDefaultPeopleDetector() -> retval

Returns coefficients of the classifier trained for people detection (for 64x128 windows).

◆ getDescriptorSize()

size_t cv::HOGDescriptor::getDescriptorSize ( ) const
Python:
cv.HOGDescriptor.getDescriptorSize() -> retval

Returns the number of coefficients required for the classification.

◆ getWinSigma()

double cv::HOGDescriptor::getWinSigma ( ) const
Python:
cv.HOGDescriptor.getWinSigma() -> retval

Returns winSigma value.

◆ groupRectangles()

void cv::HOGDescriptor::groupRectangles ( std::vector< cv::Rect > & rectList,
std::vector< double > & weights,
int groupThreshold,
double eps ) const

Groups the object candidate rectangles.

Parameters
rectListInput/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.)
weightsInput/output vector of weights of rectangles. Output vector includes weights of retained and grouped rectangles. (The Python list is not modified in place.)
groupThresholdMinimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it.
epsRelative difference between sides of the rectangles to merge them into a group.

◆ load()

virtual bool cv::HOGDescriptor::load ( const String & filename,
const String & objname = String() )
virtual
Python:
cv.HOGDescriptor.load(filename[, objname]) -> retval

loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file

Parameters
filenameName of the file to read.
objnameThe optional name of the node to read (if empty, the first top-level node will be used).

◆ read()

virtual bool cv::HOGDescriptor::read ( FileNode & fn)
virtual

Reads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file node.

Parameters
fnFile node

◆ save()

virtual void cv::HOGDescriptor::save ( const String & filename,
const String & objname = String() ) const
virtual
Python:
cv.HOGDescriptor.save(filename[, objname]) -> None

saves HOGDescriptor parameters and coefficients for the linear SVM classifier to a file

Parameters
filenameFile name
objnameObject name

◆ setSVMDetector()

virtual void cv::HOGDescriptor::setSVMDetector ( InputArray svmdetector)
virtual
Python:
cv.HOGDescriptor.setSVMDetector(svmdetector) -> None

Sets coefficients for the linear SVM classifier.

Parameters
svmdetectorcoefficients for the linear SVM classifier.
Examples
samples/peopledetect.cpp.

◆ write()

virtual void cv::HOGDescriptor::write ( FileStorage & fs,
const String & objname ) const
virtual

Stores HOGDescriptor parameters and coefficients for the linear SVM classifier in a file storage.

Parameters
fsFile storage
objnameObject name

Member Data Documentation

◆ blockSize

Size cv::HOGDescriptor::blockSize

Block size in pixels. Align to cell size. Default value is Size(16,16).

◆ blockStride

Size cv::HOGDescriptor::blockStride

Block stride. It must be a multiple of cell size. Default value is Size(8,8).

◆ cellSize

Size cv::HOGDescriptor::cellSize

Cell size. Default value is Size(8,8).

◆ derivAperture

int cv::HOGDescriptor::derivAperture

not documented

◆ free_coef

float cv::HOGDescriptor::free_coef

not documented

◆ gammaCorrection

bool cv::HOGDescriptor::gammaCorrection

Flag to specify whether the gamma correction preprocessing is required or not.

◆ histogramNormType

HOGDescriptor::HistogramNormType cv::HOGDescriptor::histogramNormType

histogramNormType

◆ L2HysThreshold

double cv::HOGDescriptor::L2HysThreshold

L2-Hys normalization method shrinkage.

◆ nbins

int cv::HOGDescriptor::nbins

Number of bins used in the calculation of histogram of gradients. Default value is 9.

◆ nlevels

int cv::HOGDescriptor::nlevels

Maximum number of detection window increases. Default value is 64.

◆ oclSvmDetector

UMat cv::HOGDescriptor::oclSvmDetector

coefficients for the linear SVM classifier used when OpenCL is enabled

◆ signedGradient

bool cv::HOGDescriptor::signedGradient

Indicates signed gradient will be used or not.

◆ svmDetector

std::vector<float> cv::HOGDescriptor::svmDetector

coefficients for the linear SVM classifier.

◆ winSigma

double cv::HOGDescriptor::winSigma

Gaussian smoothing window parameter.

◆ winSize

Size cv::HOGDescriptor::winSize

Detection window size. Align to block size and block stride. Default value is Size(64,128).


The documentation for this class was generated from the following file: