Skip to main content

Cascade Classifier

API reference for cascade-based object detection and HOG descriptor computation.

CascadeClassifier

Cascade classifier class for object detection using Haar or LBP features.

Constructor

String
Path to the classifier file (e.g., haarcascade_frontalface_default.xml)

Methods

load

Loads a classifier from a file.
String
Name of the file from which the classifier is loaded. The file may contain an old HAAR classifier trained by the haartraining application or a new cascade classifier trained by the traincascade application.
Returns: true if the classifier was loaded successfully

detectMultiScale

Detects objects of different sizes in the input image.
InputArray
Matrix of type CV_8U containing an image where objects are detected
std::vector<Rect>&
Output vector of rectangles where each rectangle contains a detected object
double
default:"1.1"
Parameter specifying how much the image size is reduced at each image scale
int
default:"3"
Parameter specifying how many neighbors each candidate rectangle should have to retain it
int
default:"0"
Parameter with the same meaning for an old cascade as in cvHaarDetectObjects. Not used for new cascades.
Size
default:"Size()"
Minimum possible object size. Objects smaller than this are ignored.
Size
default:"Size()"
Maximum possible object size. Objects larger than this are ignored. If maxSize == minSize, model is evaluated on single scale.
The function does not correct lens distortion. If camera parameters are known, it’s recommended to undistort the input image first.

detectMultiScale (with detection counts)

std::vector<int>&
Vector of detection numbers for the corresponding objects. An object’s number of detections is the number of neighboring positively classified rectangles that were joined together.

detectMultiScale (with confidence levels)

std::vector<int>&
Output vector of reject levels for each detection
std::vector<double>&
Output vector containing the certainty of classification at the final stage for each detection
bool
default:"false"
Set to true to retrieve the final stage decision certainty of classification

empty

Checks whether the classifier has been loaded.
Returns: true if the classifier is empty

Example Usage


HOGDescriptor

Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector. Based on the algorithm introduced by Navneet Dalal and Bill Triggs.

Constructor

Size
Detection window size. Default is Size(64, 128). Must align to block size and block stride.
Size
Block size in pixels. Default is Size(16, 16). Must align to cell size.
Size
Block stride. Default is Size(8, 8). Must be a multiple of cell size.
Size
Cell size. Default is Size(8, 8).
int
Number of bins used in the calculation of histogram of gradients. Default is 9.
String
File name containing HOGDescriptor properties and coefficients for the linear SVM classifier

Methods

compute

Computes HOG descriptors of given image.
InputArray
Matrix of type CV_8U containing an image where HOG features will be calculated
std::vector<float>&
Output matrix of type CV_32F containing computed descriptors
Size
default:"Size()"
Window stride. Must be a multiple of block stride.
Size
default:"Size()"
Padding around the image
std::vector<Point>
default:"empty"
Vector of specific locations to compute descriptors at

detect

Performs object detection without a multi-scale window.
InputArray
Matrix of type CV_8U or CV_8UC3 containing an image where objects are detected
std::vector<Point>&
Vector of points where each point contains left-top corner of detected object boundaries
std::vector<double>&
Vector that will contain confidence values for each detected object
double
default:"0"
Threshold for the distance between features and SVM classifying plane
Size
default:"Size()"
Window stride. Must be a multiple of block stride.
Size
default:"Size()"
Padding around the image
std::vector<Point>
default:"empty"
Vector of specific locations to search

detectMultiScale

Detects objects of different sizes in the input image.
InputArray
Matrix of type CV_8U or CV_8UC3 containing an image where objects are detected
std::vector<Rect>&
Vector of rectangles where each rectangle contains the detected object
std::vector<double>&
Vector that will contain confidence values for each detected object
double
default:"1.05"
Coefficient of the detection window increase
double
default:"2.0"
Coefficient to regulate the similarity threshold. When detected, some objects can be covered by many rectangles. 0 means not to perform grouping.
bool
default:"false"
Indicates whether to use meanshift grouping algorithm

setSVMDetector

Sets coefficients for the linear SVM classifier.
InputArray
Coefficients for the linear SVM classifier

getDefaultPeopleDetector

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

getDaimlerPeopleDetector

Returns coefficients of the classifier trained for people detection (for 48x96 windows).
Returns: Vector of SVM coefficients for Daimler people detection

Properties

  • winSize (Size): Detection window size. Default Size(64, 128).
  • blockSize (Size): Block size in pixels. Default Size(16, 16).
  • blockStride (Size): Block stride. Default Size(8, 8).
  • cellSize (Size): Cell size. Default Size(8, 8).
  • nbins (int): Number of bins. Default 9.
  • derivAperture (int): Derivative aperture.
  • winSigma (double): Gaussian smoothing window parameter.
  • histogramNormType (HistogramNormType): Histogram normalization type.
  • L2HysThreshold (double): L2-Hys normalization method shrinkage.
  • gammaCorrection (bool): Flag to specify gamma correction preprocessing.
  • svmDetector (std::vector<float>): Coefficients for the linear SVM classifier.
  • nlevels (int): Maximum number of detection window increases. Default 64.
  • signedGradient (bool): Indicates whether signed gradient will be used.

Example Usage

See Also