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

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

Methods

load

Loads a classifier from a file.
filename
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.
image
InputArray
Matrix of type CV_8U containing an image where objects are detected
objects
std::vector<Rect>&
Output vector of rectangles where each rectangle contains a detected object
scaleFactor
double
default:"1.1"
Parameter specifying how much the image size is reduced at each image scale
minNeighbors
int
default:"3"
Parameter specifying how many neighbors each candidate rectangle should have to retain it
flags
int
default:"0"
Parameter with the same meaning for an old cascade as in cvHaarDetectObjects. Not used for new cascades.
minSize
Size
default:"Size()"
Minimum possible object size. Objects smaller than this are ignored.
maxSize
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)

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

rejectLevels
std::vector<int>&
Output vector of reject levels for each detection
levelWeights
std::vector<double>&
Output vector containing the certainty of classification at the final stage for each detection
outputRejectLevels
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

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

Methods

compute

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

detect

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

detectMultiScale

Detects objects of different sizes in the input image.
img
InputArray
Matrix of type CV_8U or CV_8UC3 containing an image where objects are detected
foundLocations
std::vector<Rect>&
Vector of rectangles where each rectangle contains the detected object
foundWeights
std::vector<double>&
Vector that will contain confidence values for each detected object
scale
double
default:"1.05"
Coefficient of the detection window increase
groupThreshold
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.
useMeanshiftGrouping
bool
default:"false"
Indicates whether to use meanshift grouping algorithm

setSVMDetector

Sets coefficients for the linear SVM classifier.
svmdetector
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