Class HOGDescriptor
HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector
Implements
Inherited Members
Namespace: OpenCvSharp
Assembly: OpenCvSharp.dll
Syntax
public class HOGDescriptor : DisposableCvObject, ICvPtrHolder
Constructors
| Improve this Doc View SourceHOGDescriptor()
Default constructor
Declaration
public HOGDescriptor()
HOGDescriptor(Nullable<Size>, Nullable<Size>, Nullable<Size>, Nullable<Size>, Int32, Int32, Double, HistogramNormType, Double, Boolean, Int32)
Creates the HOG descriptor and detector.
Declaration
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
Type | Name | Description |
---|---|---|
System.Nullable<OpenCvSharp.Size> | winSize | Detection window size. Align to block size and block stride. |
System.Nullable<OpenCvSharp.Size> | blockSize | Block size in pixels. Align to cell size. Only (16,16) is supported for now. |
System.Nullable<OpenCvSharp.Size> | blockStride | Block stride. It must be a multiple of cell size. |
System.Nullable<OpenCvSharp.Size> | cellSize | Cell size. Only (8, 8) is supported for now. |
System.Int32 | nbins | Number of bins. Only 9 bins per cell are supported for now. |
System.Int32 | derivAperture | |
System.Double | winSigma | Gaussian smoothing window parameter. |
HistogramNormType | histogramNormType | |
System.Double | l2HysThreshold | L2-Hys normalization method shrinkage. |
System.Boolean | gammaCorrection | Flag to specify whether the gamma correction preprocessing is required or not. |
System.Int32 | nlevels | Maximum number of detection window increases. |
HOGDescriptor(String)
Construct from a file containing HOGDescriptor properties and coefficients for the linear SVM classifier.
Declaration
public HOGDescriptor(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | The file name containing HOGDescriptor properties and coefficients for the linear SVM classifier. |
Fields
| Improve this Doc View SourceDaimlerPeopleDetector
This field returns 1981 SVM coeffs obtained from daimler's base. To use these coeffs the detection window size should be (48,96)
Declaration
public static readonly float[] DaimlerPeopleDetector
Field Value
Type | Description |
---|---|
System.Single[] |
DefaultNlevels
Declaration
public const int DefaultNlevels = 64
Field Value
Type | Description |
---|---|
System.Int32 |
DefaultPeopleDetector
Returns coefficients of the classifier trained for people detection (for default window size).
Declaration
public static readonly float[] DefaultPeopleDetector
Field Value
Type | Description |
---|---|
System.Single[] |
L2Hys
Declaration
public const int L2Hys = 0
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
| Improve this Doc View SourceBlockSize
Block size in pixels. Align to cell size. Default value is Size(16,16).
Declaration
public Size BlockSize { get; set; }
Property Value
Type | Description |
---|---|
OpenCvSharp.Size |
BlockStride
Block stride. It must be a multiple of cell size. Default value is Size(8,8).
Declaration
public Size BlockStride { get; set; }
Property Value
Type | Description |
---|---|
OpenCvSharp.Size |
CellSize
Cell size. Default value is Size(8,8).
Declaration
public Size CellSize { get; set; }
Property Value
Type | Description |
---|---|
OpenCvSharp.Size |
DerivAperture
Declaration
public int DerivAperture { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
GammaCorrection
Flag to specify whether the gamma correction preprocessing is required or not.
Declaration
public bool GammaCorrection { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
HistogramNormType
HistogramNormType
Declaration
public HistogramNormType HistogramNormType { get; set; }
Property Value
Type | Description |
---|---|
HistogramNormType |
L2HysThreshold
L2-Hys normalization method shrinkage.
Declaration
public double L2HysThreshold { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
Nbins
Number of bins used in the calculation of histogram of gradients. Default value is 9.
Declaration
public int Nbins { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
NLevels
Maximum number of detection window increases. Default value is 64
Declaration
public int NLevels { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
SignedGradient
Indicates signed gradient will be used or not
Declaration
public bool SignedGradient { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
WinSigma
Gaussian smoothing window parameter.
Declaration
public double WinSigma { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
WinSize
Detection window size. Align to block size and block stride. Default value is Size(64,128).
Declaration
public Size WinSize { get; set; }
Property Value
Type | Description |
---|---|
OpenCvSharp.Size |
Methods
| Improve this Doc View SourceCheckDetectorSize()
Declaration
public bool CheckDetectorSize()
Returns
Type | Description |
---|---|
System.Boolean |
Compute(Mat, Nullable<Size>, Nullable<Size>, Point[])
Computes HOG descriptors of given image.
Declaration
public virtual float[] Compute(Mat img, Size? winStride = null, Size? padding = null, Point[] locations = null)
Parameters
Type | Name | Description |
---|---|---|
Mat | img | Matrix of the type CV_8U containing an image where HOG features will be calculated. |
System.Nullable<OpenCvSharp.Size> | winStride | Window stride. It must be a multiple of block stride. |
System.Nullable<OpenCvSharp.Size> | padding | Padding |
OpenCvSharp.Point[] | locations | Vector of Point |
Returns
Type | Description |
---|---|
System.Single[] | Matrix of the type CV_32F |
ComputeGradient(Mat, Mat, Mat, Nullable<Size>, Nullable<Size>)
Computes gradients and quantized gradient orientations.
Declaration
public virtual void ComputeGradient(Mat img, Mat grad, Mat angleOfs, Size? paddingTL = null, Size? paddingBR = null)
Parameters
Type | Name | Description |
---|---|---|
Mat | img | Matrix contains the image to be computed |
Mat | grad | Matrix of type CV_32FC2 contains computed gradients |
Mat | angleOfs | Matrix of type CV_8UC2 contains quantized gradient orientations |
System.Nullable<OpenCvSharp.Size> | paddingTL | Padding from top-left |
System.Nullable<OpenCvSharp.Size> | paddingBR | Padding from bottom-right |
Detect(Mat, Double, Nullable<Size>, Nullable<Size>, Point[])
Performs object detection without a multi-scale window.
Declaration
public virtual Point[] Detect(Mat img, double hitThreshold = 0, Size? winStride = null, Size? padding = null, Point[] searchLocations = null)
Parameters
Type | Name | Description |
---|---|---|
Mat | img | Source image. CV_8UC1 and CV_8UC4 types are supported for now. |
System.Double | 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. |
System.Nullable<OpenCvSharp.Size> | winStride | Window stride. It must be a multiple of block stride. |
System.Nullable<OpenCvSharp.Size> | padding | Mock parameter to keep the CPU interface compatibility. It must be (0,0). |
OpenCvSharp.Point[] | searchLocations |
Returns
Type | Description |
---|---|
OpenCvSharp.Point[] | Left-top corner points of detected objects boundaries. |
Detect(Mat, out Double[], Double, Nullable<Size>, Nullable<Size>, Point[])
Performs object detection without a multi-scale window.
Declaration
public virtual Point[] Detect(Mat img, out double[] weights, double hitThreshold = 0, Size? winStride = null, Size? padding = null, Point[] searchLocations = null)
Parameters
Type | Name | Description |
---|---|---|
Mat | img | Source image. CV_8UC1 and CV_8UC4 types are supported for now. |
System.Double[] | weights | |
System.Double | hitThreshold | 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. |
System.Nullable<OpenCvSharp.Size> | winStride | Window stride. It must be a multiple of block stride. |
System.Nullable<OpenCvSharp.Size> | padding | Mock parameter to keep the CPU interface compatibility. It must be (0,0). |
OpenCvSharp.Point[] | searchLocations |
Returns
Type | Description |
---|---|
OpenCvSharp.Point[] | Left-top corner points of detected objects boundaries. |
DetectMultiScale(Mat, Double, Nullable<Size>, Nullable<Size>, Double, Int32)
Performs object detection with a multi-scale window.
Declaration
public virtual Rect[] DetectMultiScale(Mat img, double hitThreshold = 0, Size? winStride = null, Size? padding = null, double scale = 1.05, int groupThreshold = 2)
Parameters
Type | Name | Description |
---|---|---|
Mat | img | Source image. CV_8UC1 and CV_8UC4 types are supported for now. |
System.Double | hitThreshold | Threshold for the distance between features and SVM classifying plane. |
System.Nullable<OpenCvSharp.Size> | winStride | Window stride. It must be a multiple of block stride. |
System.Nullable<OpenCvSharp.Size> | padding | Mock parameter to keep the CPU interface compatibility. It must be (0,0). |
System.Double | scale | Coefficient of the detection window increase. |
System.Int32 | groupThreshold | Coefficient to regulate the similarity threshold. When detected, some objects can be covered by many rectangles. 0 means not to perform grouping. |
Returns
Type | Description |
---|---|
OpenCvSharp.Rect[] | Detected objects boundaries. |
DetectMultiScale(Mat, out Double[], Double, Nullable<Size>, Nullable<Size>, Double, Int32)
Performs object detection with a multi-scale window.
Declaration
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
Type | Name | Description |
---|---|---|
Mat | img | Source image. CV_8UC1 and CV_8UC4 types are supported for now. |
System.Double[] | foundWeights | |
System.Double | hitThreshold | Threshold for the distance between features and SVM classifying plane. |
System.Nullable<OpenCvSharp.Size> | winStride | Window stride. It must be a multiple of block stride. |
System.Nullable<OpenCvSharp.Size> | padding | Mock parameter to keep the CPU interface compatibility. It must be (0,0). |
System.Double | scale | Coefficient of the detection window increase. |
System.Int32 | groupThreshold | Coefficient to regulate the similarity threshold. When detected, some objects can be covered by many rectangles. 0 means not to perform grouping. |
Returns
Type | Description |
---|---|
OpenCvSharp.Rect[] | Detected objects boundaries. |
DetectMultiScaleROI(Mat, out Rect[], out DetectionROI[], Double, Int32)
evaluate specified ROI and return confidence value for each location in multiple scales
Declaration
public void DetectMultiScaleROI(Mat img, out Rect[] foundLocations, out DetectionROI[] locations, double hitThreshold = 0, int groupThreshold = 0)
Parameters
Type | Name | Description |
---|---|---|
Mat | img | Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. |
OpenCvSharp.Rect[] | foundLocations | Vector of rectangles where each rectangle contains the detected object. |
DetectionROI[] | locations | Vector of DetectionROI |
System.Double | 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. |
System.Int32 | groupThreshold | 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, Nullable<Size>, Nullable<Size>)
evaluate specified ROI and return confidence value for each location
Declaration
public void DetectROI(Mat img, Point[] locations, out Point[] foundLocations, out double[] confidences, double hitThreshold = 0, Size? winStride = null, Size? padding = null)
Parameters
Type | Name | Description |
---|---|---|
Mat | img | Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. |
OpenCvSharp.Point[] | locations | Vector of Point |
OpenCvSharp.Point[] | foundLocations | Vector of Point where each Point is detected object's top-left point. |
System.Double[] | confidences | confidences |
System.Double | 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 |
System.Nullable<OpenCvSharp.Size> | winStride | winStride |
System.Nullable<OpenCvSharp.Size> | padding | padding |
DisposeUnmanaged()
Releases unmanaged resources
Declaration
protected override void DisposeUnmanaged()
Overrides
| Improve this Doc View SourceGetDaimlerPeopleDetector()
This method returns 1981 SVM coeffs obtained from daimler's base. To use these coeffs the detection window size should be (48,96)
Declaration
public static float[] GetDaimlerPeopleDetector()
Returns
Type | Description |
---|---|
System.Single[] |
GetDefaultPeopleDetector()
Returns coefficients of the classifier trained for people detection (for default window size).
Declaration
public static float[] GetDefaultPeopleDetector()
Returns
Type | Description |
---|---|
System.Single[] |
GetDescriptorSize()
Declaration
public int GetDescriptorSize()
Returns
Type | Description |
---|---|
System.Int32 |
GetWinSigma()
Declaration
public double GetWinSigma()
Returns
Type | Description |
---|---|
System.Double |
GroupRectangles(out Rect[], out Double[], Int32, Double)
Groups the object candidate rectangles.
Declaration
public void GroupRectangles(out Rect[] rectList, out double[] weights, int groupThreshold, double eps)
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.Rect[] | rectList | Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.) |
System.Double[] | 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.) |
System.Int32 | groupThreshold | Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. |
System.Double | eps | 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.
Declaration
public virtual bool Load(string fileName, string objName = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | Path of the file to read. |
System.String | objName | The optional name of the node to read (if empty, the first top-level node will be used). |
Returns
Type | Description |
---|---|
System.Boolean |
Save(String, String)
saves HOGDescriptor parameters and coefficients for the linear SVM classifier to a file
Declaration
public virtual void Save(string fileName, string objName = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | File name |
System.String | objName | Object name |
SetSVMDetector(Single[])
Sets coefficients for the linear SVM classifier.
Declaration
public virtual void SetSVMDetector(float[] svmDetector)
Parameters
Type | Name | Description |
---|---|---|
System.Single[] | svmDetector | coefficients for the linear SVM classifier. |