Table of Contents

Class HOGDescriptor

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector

public class HOGDescriptor : DisposableCvObject, IDisposable, ICvPtrHolder
Inheritance
HOGDescriptor
Implements
Inherited Members

Constructors

HOGDescriptor()

Default constructor

public HOGDescriptor()

HOGDescriptor(Size?, Size?, Size?, Size?, int, int, double, HistogramNormType, double, bool, int)

Creates the HOG descriptor and detector.

public HOGDescriptor(Size? winSize = null, Size? blockSize = null, Size? blockStride = null, Size? cellSize = null, int nbins = 9, int derivAperture = 1, double winSigma = -1, HistogramNormType histogramNormType = HistogramNormType.L2Hys, double l2HysThreshold = 0.2, bool gammaCorrection = true, int nlevels = 64)

Parameters

winSize Size?

Detection window size. Align to block size and block stride.

blockSize Size?

Block size in pixels. Align to cell size. Only (16,16) is supported for now.

blockStride Size?

Block stride. It must be a multiple of cell size.

cellSize Size?

Cell size. Only (8, 8) is supported for now.

nbins int

Number of bins. Only 9 bins per cell are supported for now.

derivAperture int
winSigma double

Gaussian smoothing window parameter.

histogramNormType HistogramNormType
l2HysThreshold double

L2-Hys normalization method shrinkage.

gammaCorrection bool

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

nlevels int

Maximum number of detection window increases.

HOGDescriptor(string)

Construct from a file containing HOGDescriptor properties and coefficients for the linear SVM classifier.

public HOGDescriptor(string fileName)

Parameters

fileName string

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

Fields

DaimlerPeopleDetector

This field returns 1981 SVM coeffs obtained from daimler's base. To use these coeffs the detection window size should be (48,96)

public static readonly float[] DaimlerPeopleDetector

Field Value

float[]

DefaultNlevels

public const int DefaultNlevels = 64

Field Value

int

DefaultPeopleDetector

Returns coefficients of the classifier trained for people detection (for default window size).

public static readonly float[] DefaultPeopleDetector

Field Value

float[]

L2Hys

public const int L2Hys = 0

Field Value

int

Properties

BlockSize

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

public Size BlockSize { get; set; }

Property Value

Size

BlockStride

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

public Size BlockStride { get; set; }

Property Value

Size

CellSize

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

public Size CellSize { get; set; }

Property Value

Size

DerivAperture

public int DerivAperture { get; set; }

Property Value

int

GammaCorrection

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

public bool GammaCorrection { get; set; }

Property Value

bool

HistogramNormType

HistogramNormType

public HistogramNormType HistogramNormType { get; set; }

Property Value

HistogramNormType

L2HysThreshold

L2-Hys normalization method shrinkage.

public double L2HysThreshold { get; set; }

Property Value

double

NLevels

Maximum number of detection window increases. Default value is 64

public int NLevels { get; set; }

Property Value

int

Nbins

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

public int Nbins { get; set; }

Property Value

int

SignedGradient

Indicates signed gradient will be used or not

public bool SignedGradient { get; set; }

Property Value

bool

WinSigma

Gaussian smoothing window parameter.

public double WinSigma { get; set; }

Property Value

double

WinSize

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

public Size WinSize { get; set; }

Property Value

Size

Methods

CheckDetectorSize()

public bool CheckDetectorSize()

Returns

bool

Compute(Mat, Size?, Size?, Point[]?)

Computes HOG descriptors of given image.

public virtual float[] Compute(Mat img, Size? winStride = null, Size? padding = null, Point[]? locations = null)

Parameters

img Mat

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

winStride Size?

Window stride. It must be a multiple of block stride.

padding Size?

Padding

locations Point[]

Vector of Point

Returns

float[]

Matrix of the type CV_32F

ComputeGradient(Mat, Mat, Mat, Size?, Size?)

Computes gradients and quantized gradient orientations.

public virtual void ComputeGradient(Mat img, Mat grad, Mat angleOfs, Size? paddingTL = null, Size? paddingBR = null)

Parameters

img Mat

Matrix contains the image to be computed

grad Mat

Matrix of type CV_32FC2 contains computed gradients

angleOfs Mat

Matrix of type CV_8UC2 contains quantized gradient orientations

paddingTL Size?

Padding from top-left

paddingBR Size?

Padding from bottom-right

Detect(Mat, double, Size?, Size?, Point[]?)

Performs object detection without a multi-scale window.

public virtual Point[] Detect(Mat img, double hitThreshold = 0, Size? winStride = null, Size? padding = null, Point[]? searchLocations = null)

Parameters

img Mat

Source image. CV_8UC1 and CV_8UC4 types are supported for now.

hitThreshold double

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 Size?

Window stride. It must be a multiple of block stride.

padding Size?

Mock parameter to keep the CPU interface compatibility. It must be (0,0).

searchLocations Point[]

Returns

Point[]

Left-top corner points of detected objects boundaries.

Detect(Mat, out double[], double, Size?, Size?, Point[]?)

Performs object detection without a multi-scale window.

public virtual Point[] Detect(Mat img, out double[] weights, double hitThreshold = 0, Size? winStride = null, Size? padding = null, Point[]? searchLocations = null)

Parameters

img Mat

Source image. CV_8UC1 and CV_8UC4 types are supported for now.

weights double[]
hitThreshold double

Threshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specfied 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 Size?

Window stride. It must be a multiple of block stride.

padding Size?

Mock parameter to keep the CPU interface compatibility. It must be (0,0).

searchLocations Point[]

Returns

Point[]

Left-top corner points of detected objects boundaries.

DetectMultiScale(Mat, double, Size?, Size?, double, int)

Performs object detection with a multi-scale window.

public virtual Rect[] DetectMultiScale(Mat img, double hitThreshold = 0, Size? winStride = null, Size? padding = null, double scale = 1.05, int groupThreshold = 2)

Parameters

img Mat

Source image. CV_8UC1 and CV_8UC4 types are supported for now.

hitThreshold double

Threshold for the distance between features and SVM classifying plane.

winStride Size?

Window stride. It must be a multiple of block stride.

padding Size?

Mock parameter to keep the CPU interface compatibility. It must be (0,0).

scale double

Coefficient of the detection window increase.

groupThreshold int

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

Returns

Rect[]

Detected objects boundaries.

DetectMultiScale(Mat, out double[], double, Size?, Size?, double, int)

Performs object detection with a multi-scale window.

public virtual Rect[] DetectMultiScale(Mat img, out double[] foundWeights, double hitThreshold = 0, Size? winStride = null, Size? padding = null, double scale = 1.05, int groupThreshold = 2)

Parameters

img Mat

Source image. CV_8UC1 and CV_8UC4 types are supported for now.

foundWeights double[]
hitThreshold double

Threshold for the distance between features and SVM classifying plane.

winStride Size?

Window stride. It must be a multiple of block stride.

padding Size?

Mock parameter to keep the CPU interface compatibility. It must be (0,0).

scale double

Coefficient of the detection window increase.

groupThreshold int

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

Returns

Rect[]

Detected objects boundaries.

DetectMultiScaleROI(Mat, out Rect[], out DetectionROI[], double, int)

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

public void DetectMultiScaleROI(Mat img, out Rect[] foundLocations, out DetectionROI[] locations, double hitThreshold = 0, int groupThreshold = 0)

Parameters

img Mat

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

foundLocations Rect[]

Vector of rectangles where each rectangle contains the detected object.

locations DetectionROI[]

Vector of DetectionROI

hitThreshold double

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 int

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

DetectROI(Mat, Point[], out Point[], out double[], double, Size?, Size?)

evaluate specified ROI and return confidence value for each location

public void DetectROI(Mat img, Point[] locations, out Point[] foundLocations, out double[] confidences, double hitThreshold = 0, Size? winStride = null, Size? padding = null)

Parameters

img Mat

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

locations Point[]

Vector of Point

foundLocations Point[]

Vector of Point where each Point is detected object's top-left point.

confidences double[]

confidences

hitThreshold double

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 Size?

winStride

padding Size?

padding

DisposeUnmanaged()

Releases unmanaged resources

protected override void DisposeUnmanaged()

GetDaimlerPeopleDetector()

This method returns 1981 SVM coeffs obtained from daimler's base. To use these coeffs the detection window size should be (48,96)

public static float[] GetDaimlerPeopleDetector()

Returns

float[]

GetDefaultPeopleDetector()

Returns coefficients of the classifier trained for people detection (for default window size).

public static float[] GetDefaultPeopleDetector()

Returns

float[]

GetDescriptorSize()

public int GetDescriptorSize()

Returns

int

GetWinSigma()

public double GetWinSigma()

Returns

double

GroupRectangles(out Rect[], out double[], int, double)

Groups the object candidate rectangles.

public void GroupRectangles(out Rect[] rectList, out double[] weights, int groupThreshold, double eps)

Parameters

rectList Rect[]

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

weights double[]

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 int

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

eps double

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

Load(string, string?)

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

public virtual bool Load(string fileName, string? objName = null)

Parameters

fileName string

Path of the file to read.

objName string

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

Returns

bool

Save(string, string?)

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

public virtual void Save(string fileName, string? objName = null)

Parameters

fileName string

File name

objName string

Object name

SetSVMDetector(float[])

Sets coefficients for the linear SVM classifier.

public virtual void SetSVMDetector(float[] svmDetector)

Parameters

svmDetector float[]

coefficients for the linear SVM classifier.