HOG (Histogram of Oriented Gradients) descriptor and object detector#

Classes#

Name

Description

struct cv::DetectionROI

struct for detection region of interest (ROI)

class cv::HOGDescriptor

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

Struct cv::DetectionROI#

struct for detection region of interest (ROI)

Collaboration diagram for cv::DetectionROI:

cv::DetectionROI Node1 cv::DetectionROI     Node2 double     Node2->Node1 +scale Node8 std::vector< double >     Node2->Node8 +elements Node3 std::vector< cv::Point_ >     Node3->Node1 +locations Node4 cv::Point_< _Tp >   + Point_() + Point_() + Point_() + Point_() + Point_() + Point_() + cross() + ddot() + dot() + inside() + operator Point_< _Tp2 >() + operator Vec< _Tp, 2 >() + operator=() + operator=() Node4->Node3 +elements Node5 _Tp     Node5->Node4 +x +y Node6 std::vector< T >     Node6->Node3 < cv::Point_ > Node6->Node8 < double > Node7 T     Node7->Node6 +elements Node8->Node1 +confidences

cv::DetectionROI Node1 cv::DetectionROI     Node2 double     Node2->Node1 +scale Node8 std::vector< double >     Node2->Node8 +elements Node3 std::vector< cv::Point_ >     Node3->Node1 +locations Node4 cv::Point_< _Tp >   + Point_() + Point_() + Point_() + Point_() + Point_() + Point_() + cross() + ddot() + dot() + inside() + operator Point_< _Tp2 >() + operator Vec< _Tp, 2 >() + operator=() + operator=() Node4->Node3 +elements Node5 _Tp     Node5->Node4 +x +y Node6 std::vector< T >     Node6->Node3 < cv::Point_ > Node6->Node8 < double > Node7 T     Node7->Node6 +elements Node8->Node1 +confidences

Detailed Description#

struct for detection region of interest (ROI)

Member Data Documentation#

confidences#

std::vector< double > cv::DetectionROI::confidences

vector that will contain confidence values for each location

locations#

std::vector< cv::Point > cv::DetectionROI::locations

set of requested locations to be evaluated

scale#

double cv::DetectionROI::scale

scale(size) of the bounding box

Source file#

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

Class cv::HOGDescriptor#

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

Collaboration diagram for cv::HOGDescriptor:

cv::HOGDescriptor Node1 cv::HOGDescriptor   + HOGDescriptor() + HOGDescriptor() + HOGDescriptor() + ~HOGDescriptor() + checkDetectorSize() + compute() + computeGradient() + copyTo() + detect() + detect() and 12 more... + getDaimlerPeopleDetector() + getDefaultPeopleDetector() Node2 cv::Size_< _Tp >   + Size_() + Size_() + Size_() + Size_() + Size_() + area() + aspectRatio() + empty() + operator Size_< _Tp2 >() + operator=() + operator=() Node2->Node1 +blockSize +blockStride +cellSize +winSize Node3 _Tp     Node3->Node2 +height +width Node4 int     Node4->Node1 +derivAperture +nbins +nlevels Node12 cv::UMat   + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() and 67 more... + diag() + eye() + eye() + getStdAllocator() + ones() + ones() + ones() + ones() + zeros() + zeros() + zeros() + zeros() Node4->Node12 +cols +dims +flags +rows Node5 double     Node5->Node1 +L2HysThreshold +winSigma Node6 HistogramNormType     Node6->Node1 +histogramNormType Node7 bool     Node7->Node1 +gammaCorrection +signedGradient Node8 std::vector< float >     Node8->Node1 +svmDetector Node9 float     Node9->Node1 +free_coef Node9->Node8 +elements Node10 std::vector< T >     Node10->Node8 < float > Node11 T     Node11->Node10 +elements Node12->Node1 +oclSvmDetector Node13 cv::MatAllocator   + MatAllocator() + ~MatAllocator() + allocate() + allocate() + copy() + deallocate() + download() + getBufferPoolController() + map() + unmap() + upload() Node13->Node12 +allocator Node14 UMatUsageFlags     Node14->Node12 +usageFlags Node15 UMatData *     Node15->Node12 +u Node16 size_t     Node16->Node12 +offset Node17 MatSize     Node17->Node12 +size Node18 MatStep     Node18->Node12 +step

cv::HOGDescriptor Node1 cv::HOGDescriptor   + HOGDescriptor() + HOGDescriptor() + HOGDescriptor() + ~HOGDescriptor() + checkDetectorSize() + compute() + computeGradient() + copyTo() + detect() + detect() and 12 more... + getDaimlerPeopleDetector() + getDefaultPeopleDetector() Node2 cv::Size_< _Tp >   + Size_() + Size_() + Size_() + Size_() + Size_() + area() + aspectRatio() + empty() + operator Size_< _Tp2 >() + operator=() + operator=() Node2->Node1 +blockSize +blockStride +cellSize +winSize Node3 _Tp     Node3->Node2 +height +width Node4 int     Node4->Node1 +derivAperture +nbins +nlevels Node12 cv::UMat   + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() + UMat() and 67 more... + diag() + eye() + eye() + getStdAllocator() + ones() + ones() + ones() + ones() + zeros() + zeros() + zeros() + zeros() Node4->Node12 +cols +dims +flags +rows Node5 double     Node5->Node1 +L2HysThreshold +winSigma Node6 HistogramNormType     Node6->Node1 +histogramNormType Node7 bool     Node7->Node1 +gammaCorrection +signedGradient Node8 std::vector< float >     Node8->Node1 +svmDetector Node9 float     Node9->Node1 +free_coef Node9->Node8 +elements Node10 std::vector< T >     Node10->Node8 < float > Node11 T     Node11->Node10 +elements Node12->Node1 +oclSvmDetector Node13 cv::MatAllocator   + MatAllocator() + ~MatAllocator() + allocate() + allocate() + copy() + deallocate() + download() + getBufferPoolController() + map() + unmap() + upload() Node13->Node12 +allocator Node14 UMatUsageFlags     Node14->Node12 +usageFlags Node15 UMatData *     Node15->Node12 +u Node16 size_t     Node16->Node12 +offset Node17 MatSize     Node17->Node12 +size Node18 MatStep     Node18->Node12 +step

Public Types#

Detailed Description#

class HOGDescriptor#

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

the HOG descriptor algorithm introduced by Navneet Dalal and Bill Triggs Dalal2005 .

useful links:

https://hal.inria.fr/inria-00548512/document/

https://en.wikipedia.org/wiki/Histogram_of_oriented_gradients

https://software.intel.com/en-us/ipp-dev-reference-histogram-of-oriented-gradients-hog-descriptor

http://www.learnopencv.com/histogram-of-oriented-gradients

http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial

Examples
samples/hog_tapi.cpp, and samples/peopledetect.cpp.

Member Enumeration Documentation#

enum HOGDescriptor

DEFAULT_NLEVELS

Default nlevels value.

enum DescriptorStorageFormat

DESCR_FORMAT_COL_BY_COL
Python: cv.HOGDescriptor_DESCR_FORMAT_COL_BY_COL

DESCR_FORMAT_ROW_BY_ROW
Python: cv.HOGDescriptor_DESCR_FORMAT_ROW_BY_ROW

enum HistogramNormType

L2Hys
Python: cv.HOGDescriptor_L2Hys

Default histogramNormType.

Constructor & Destructor Documentation#

HOGDescriptor()#

cv::HOGDescriptor::HOGDescriptor(const HOGDescriptor & d)

Python:

cv.HOGDescriptor([, _winSize[, _blockSize[, _blockStride[, _cellSize[, _nbins[, _derivAperture[, _winSigma[, _histogramNormType[, _L2HysThreshold[, _gammaCorrection[, _nlevels[, _signedGradient]]]]]]]]]]]]) -> <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

Here is the call graph for this function:

cv::HOGDescriptor::HOGDescriptor Node1 cv::HOGDescriptor:: HOGDescriptor Node2 cv::HOGDescriptor:: copyTo Node1->Node2

cv::HOGDescriptor::HOGDescriptor Node1 cv::HOGDescriptor:: HOGDescriptor Node2 cv::HOGDescriptor:: copyTo Node1->Node2

HOGDescriptor()#

cv::HOGDescriptor::HOGDescriptor(const String & filename)

Python:

cv.HOGDescriptor([, _winSize[, _blockSize[, _blockStride[, _cellSize[, _nbins[, _derivAperture[, _winSigma[, _histogramNormType[, _L2HysThreshold[, _gammaCorrection[, _nlevels[, _signedGradient]]]]]]]]]]]]) -> <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

  • filename — The file name containing HOGDescriptor properties and coefficients for the linear SVM classifier.

HOGDescriptor()#

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 )

Python:

cv.HOGDescriptor([, _winSize[, _blockSize[, _blockStride[, _cellSize[, _nbins[, _derivAperture[, _winSigma[, _histogramNormType[, _L2HysThreshold[, _gammaCorrection[, _nlevels[, _signedGradient]]]]]]]]]]]]) -> <HOGDescriptor object>

Creates the HOG descriptor and detector with default parameters.

Parameters

  • _winSize — sets winSize with given value.

  • _blockSize — sets blockSize with given value.

  • _blockStride — sets blockStride with given value.

  • _cellSize — sets cellSize with given value.

  • _nbins — sets nbins with given value.

  • _derivAperture — sets derivAperture with given value.

  • _winSigma — sets winSigma with given value.

  • _histogramNormType — sets histogramNormType with given value.

  • _L2HysThreshold — sets L2HysThreshold with given value.

  • _gammaCorrection — sets gammaCorrection with given value.

  • _nlevels — sets nlevels with given value.

  • _signedGradient — sets signedGradient with given value.

~HOGDescriptor()#

cv::HOGDescriptor::~HOGDescriptor()

Default destructor.

Member Function Documentation#

checkDetectorSize()#

bool cv::HOGDescriptor::checkDetectorSize()

Python:

cv.HOGDescriptor.checkDetectorSize() -> retval

Checks if detector size equal to descriptor size.

compute()#

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

Python:

cv.HOGDescriptor.compute(img[, winStride[, padding[, locations]]]) -> descriptors

Computes HOG descriptors of given image.

Parameters

  • img — Matrix of the type CV_8U containing an image where HOG features will be calculated.

  • descriptors — Matrix of the type CV_32F

  • winStride — Window stride. It must be a multiple of block stride.

  • padding — Padding

  • locations — Vector of Point

computeGradient()#

void cv::HOGDescriptor::computeGradient(
InputArray img,
InputOutputArray grad,
InputOutputArray angleOfs,
Size paddingTL = Size(),
Size paddingBR = Size() )

Python:

cv.HOGDescriptor.computeGradient(img, grad, angleOfs[, paddingTL[, paddingBR]]) -> grad, angleOfs

Computes gradients and quantized gradient orientations.

Parameters

  • img — Matrix contains the image to be computed

  • grad — Matrix of type CV_32FC2 contains computed gradients

  • angleOfs — Matrix of type CV_8UC2 contains quantized gradient orientations

  • paddingTL — Padding from top-left

  • paddingBR — Padding from bottom-right

copyTo()#

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

clones the HOGDescriptor

Parameters

detect()#

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 >() )

Python:

cv.HOGDescriptor.detect(img[, hitThreshold[, winStride[, padding[, searchLocations]]]]) -> foundLocations, weights

Performs object detection without a multi-scale window.

Parameters

  • img — Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.

  • foundLocations — Vector of point where each point contains left-top corner point of detected object boundaries.

  • hitThreshold — Threshold 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.

  • winStride — Window stride. It must be a multiple of block stride.

  • padding — Padding

  • searchLocations — Vector of Point includes locations to search.

detect()#

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 >() )

Python:

cv.HOGDescriptor.detect(img[, hitThreshold[, winStride[, padding[, searchLocations]]]]) -> foundLocations, weights

Performs object detection without a multi-scale window.

Parameters

  • img — Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.

  • foundLocations — Vector of point where each point contains left-top corner point of detected object boundaries.

  • weights — Vector that will contain confidence values for each detected object.

  • hitThreshold — Threshold 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.

  • winStride — Window stride. It must be a multiple of block stride.

  • padding — Padding

  • searchLocations — Vector of Point includes set of requested locations to be evaluated.

detectMultiScale()#

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 )

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

  • img — Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.

  • foundLocations — Vector of rectangles where each rectangle contains the detected object.

  • hitThreshold — Threshold 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.

  • winStride — Window stride. It must be a multiple of block stride.

  • padding — Padding

  • scale — Coefficient of the detection window increase.

  • groupThreshold — Coefficient to regulate the similarity threshold. When detected, some objects can be covered by many rectangles. 0 means not to perform grouping.

  • useMeanshiftGrouping — indicates grouping algorithm

detectMultiScale()#

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 )

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

  • img — Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.

  • foundLocations — Vector of rectangles where each rectangle contains the detected object.

  • foundWeights — Vector that will contain confidence values for each detected object.

  • hitThreshold — Threshold 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.

  • winStride — Window stride. It must be a multiple of block stride.

  • padding — Padding

  • scale — Coefficient of the detection window increase.

  • groupThreshold — Coefficient to regulate the similarity threshold. When detected, some objects can be covered by many rectangles. 0 means not to perform grouping.

  • useMeanshiftGrouping — indicates grouping algorithm

detectMultiScaleROI()#

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

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

Parameters

  • img — Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.

  • foundLocations — Vector of rectangles where each rectangle contains the detected object.

  • locations — Vector of DetectionROI

  • hitThreshold — Threshold 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.

  • groupThreshold — Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it.

detectROI()#

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() )

evaluate specified ROI and return confidence value for each location

Parameters

  • img — Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.

  • locations — Vector of Point

  • foundLocations — Vector of Point where each Point is detected object’s top-left point.

  • confidences — confidences

  • hitThreshold — Threshold 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

  • winStride — winStride

  • padding — padding

getDescriptorSize()#

size_t cv::HOGDescriptor::getDescriptorSize()

Python:

cv.HOGDescriptor.getDescriptorSize() -> retval

Returns the number of coefficients required for the classification.

getWinSigma()#

double cv::HOGDescriptor::getWinSigma()

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 )

Groups the object candidate rectangles.

Parameters

  • rectList — Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.)

  • 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.)

  • groupThreshold — Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it.

  • eps — Relative difference between sides of the rectangles to merge them into a group.

load()#

bool cv::HOGDescriptor::load(
const String & filename,
const String & objname = String() )

Python:

cv.HOGDescriptor.load(filename[, objname]) -> retval

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

Parameters

  • filename — Name of the file to read.

  • objname — The optional name of the node to read (if empty, the first top-level node will be used).

read()#

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

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

Parameters

  • fn — File node

save()#

void cv::HOGDescriptor::save(
const String & filename,
const String & objname = String() )

Python:

cv.HOGDescriptor.save(filename[, objname])

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

Parameters

  • filename — File name

  • objname — Object name

setSVMDetector()#

void cv::HOGDescriptor::setSVMDetector(InputArray svmdetector)

Python:

cv.HOGDescriptor.setSVMDetector(svmdetector)

Sets coefficients for the linear SVM classifier.

Parameters

  • svmdetector — coefficients for the linear SVM classifier.

write()#

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

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

Parameters

  • fs — File storage

  • objname — Object name

getDaimlerPeopleDetector()#

static std::vector< float > cv::HOGDescriptor::getDaimlerPeopleDetector()

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()

Python:

cv.HOGDescriptor.getDefaultPeopleDetector() -> retval
cv.HOGDescriptor_getDefaultPeopleDetector() -> retval

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

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).

Source file#

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