• java.lang.Object

• public class CascadeClassifier
extends java.lang.Object
Cascade classifier class for object detection.
• ### Field Summary

Fields
Modifier and Type Field Description
protected long nativeObj
• ### Constructor Summary

Constructors
Modifier Constructor Description
  CascadeClassifier()
protected  CascadeClassifier​(long addr)
  CascadeClassifier​(java.lang.String filename)
Loads a classifier from a file.
• ### Method Summary

All Methods
Modifier and Type Method Description
static CascadeClassifier __fromPtr__​(long addr)
static boolean convert​(java.lang.String oldcascade, java.lang.String newcascade)
void detectMultiScale​(Mat image, MatOfRect objects)
Detects objects of different sizes in the input image.
void detectMultiScale​(Mat image, MatOfRect objects, double scaleFactor)
Detects objects of different sizes in the input image.
void detectMultiScale​(Mat image, MatOfRect objects, double scaleFactor, int minNeighbors)
Detects objects of different sizes in the input image.
void detectMultiScale​(Mat image, MatOfRect objects, double scaleFactor, int minNeighbors, int flags)
Detects objects of different sizes in the input image.
void detectMultiScale​(Mat image, MatOfRect objects, double scaleFactor, int minNeighbors, int flags, Size minSize)
Detects objects of different sizes in the input image.
void detectMultiScale​(Mat image, MatOfRect objects, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize)
Detects objects of different sizes in the input image.
void detectMultiScale2​(Mat image, MatOfRect objects, MatOfInt numDetections)
void detectMultiScale2​(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor)
void detectMultiScale2​(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor, int minNeighbors)
void detectMultiScale2​(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor, int minNeighbors, int flags)
void detectMultiScale2​(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor, int minNeighbors, int flags, Size minSize)
void detectMultiScale2​(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize)
void detectMultiScale3​(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights)
This function allows you to retrieve the final stage decision certainty of classification.
void detectMultiScale3​(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor)
This function allows you to retrieve the final stage decision certainty of classification.
void detectMultiScale3​(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors)
This function allows you to retrieve the final stage decision certainty of classification.
void detectMultiScale3​(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors, int flags)
This function allows you to retrieve the final stage decision certainty of classification.
void detectMultiScale3​(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors, int flags, Size minSize)
This function allows you to retrieve the final stage decision certainty of classification.
void detectMultiScale3​(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize)
This function allows you to retrieve the final stage decision certainty of classification.
void detectMultiScale3​(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize, boolean outputRejectLevels)
This function allows you to retrieve the final stage decision certainty of classification.
boolean empty()
Checks whether the classifier has been loaded.
protected void finalize()
int getFeatureType()
long getNativeObjAddr()
Size getOriginalWindowSize()
boolean isOldFormatCascade()
boolean load​(java.lang.String filename)
Loads a classifier from a file.
• ### Methods inherited from class java.lang.Object

clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Field Detail

• #### nativeObj

protected final long nativeObj
• ### Constructor Detail

protected CascadeClassifier​(long addr)

public CascadeClassifier()

public CascadeClassifier​(java.lang.String filename)
Loads a classifier from a file.
Parameters:
filename - Name of the file from which the classifier is loaded.
• ### Method Detail

public long getNativeObjAddr()
• #### __fromPtr__

public static CascadeClassifier __fromPtr__​(long addr)
• #### empty

public boolean empty()
Checks whether the classifier has been loaded.
Returns:
automatically generated

public boolean load​(java.lang.String filename)
Loads a classifier from a file.
Parameters:
filename - 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:
automatically generated
• #### detectMultiScale

public void detectMultiScale​(Mat image,
MatOfRect objects,
double scaleFactor,
int minNeighbors,
int flags,
Size minSize,
Size maxSize)
Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale.
minNeighbors - Parameter specifying how many neighbors each candidate rectangle should have to retain it.
flags - Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
minSize - Minimum possible object size. Objects smaller than that are ignored.
maxSize - Maximum possible object size. Objects larger than that are ignored. If maxSize == minSize model is evaluated on single scale. The function is parallelized with the TBB library. Note:
• (Python) A face detection example using cascade classifiers can be found at opencv_source_code/samples/python/facedetect.py
• #### detectMultiScale

public void detectMultiScale​(Mat image,
MatOfRect objects,
double scaleFactor,
int minNeighbors,
int flags,
Size minSize)
Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale.
minNeighbors - Parameter specifying how many neighbors each candidate rectangle should have to retain it.
flags - Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
minSize - Minimum possible object size. Objects smaller than that are ignored. The function is parallelized with the TBB library. Note:
• (Python) A face detection example using cascade classifiers can be found at opencv_source_code/samples/python/facedetect.py
• #### detectMultiScale

public void detectMultiScale​(Mat image,
MatOfRect objects,
double scaleFactor,
int minNeighbors,
int flags)
Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale.
minNeighbors - Parameter specifying how many neighbors each candidate rectangle should have to retain it.
flags - Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade. The function is parallelized with the TBB library. Note:
• (Python) A face detection example using cascade classifiers can be found at opencv_source_code/samples/python/facedetect.py
• #### detectMultiScale

public void detectMultiScale​(Mat image,
MatOfRect objects,
double scaleFactor,
int minNeighbors)
Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale.
minNeighbors - Parameter specifying how many neighbors each candidate rectangle should have to retain it. cvHaarDetectObjects. It is not used for a new cascade. The function is parallelized with the TBB library. Note:
• (Python) A face detection example using cascade classifiers can be found at opencv_source_code/samples/python/facedetect.py
• #### detectMultiScale

public void detectMultiScale​(Mat image,
MatOfRect objects,
double scaleFactor)
Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale. to retain it. cvHaarDetectObjects. It is not used for a new cascade. The function is parallelized with the TBB library. Note:
• (Python) A face detection example using cascade classifiers can be found at opencv_source_code/samples/python/facedetect.py
• #### detectMultiScale

public void detectMultiScale​(Mat image,
MatOfRect objects)
Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image. to retain it. cvHaarDetectObjects. It is not used for a new cascade. The function is parallelized with the TBB library. Note:
• (Python) A face detection example using cascade classifiers can be found at opencv_source_code/samples/python/facedetect.py
• #### detectMultiScale2

public void detectMultiScale2​(Mat image,
MatOfRect objects,
MatOfInt numDetections,
double scaleFactor,
int minNeighbors,
int flags,
Size minSize,
Size maxSize)
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
numDetections - 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 to form the object.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale.
minNeighbors - Parameter specifying how many neighbors each candidate rectangle should have to retain it.
flags - Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
minSize - Minimum possible object size. Objects smaller than that are ignored.
maxSize - Maximum possible object size. Objects larger than that are ignored. If maxSize == minSize model is evaluated on single scale.
• #### detectMultiScale2

public void detectMultiScale2​(Mat image,
MatOfRect objects,
MatOfInt numDetections,
double scaleFactor,
int minNeighbors,
int flags,
Size minSize)
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
numDetections - 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 to form the object.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale.
minNeighbors - Parameter specifying how many neighbors each candidate rectangle should have to retain it.
flags - Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
minSize - Minimum possible object size. Objects smaller than that are ignored.
• #### detectMultiScale2

public void detectMultiScale2​(Mat image,
MatOfRect objects,
MatOfInt numDetections,
double scaleFactor,
int minNeighbors,
int flags)
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
numDetections - 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 to form the object.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale.
minNeighbors - Parameter specifying how many neighbors each candidate rectangle should have to retain it.
flags - Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
• #### detectMultiScale2

public void detectMultiScale2​(Mat image,
MatOfRect objects,
MatOfInt numDetections,
double scaleFactor,
int minNeighbors)
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
numDetections - 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 to form the object.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale.
minNeighbors - Parameter specifying how many neighbors each candidate rectangle should have to retain it. cvHaarDetectObjects. It is not used for a new cascade.
• #### detectMultiScale2

public void detectMultiScale2​(Mat image,
MatOfRect objects,
MatOfInt numDetections,
double scaleFactor)
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
numDetections - 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 to form the object.
scaleFactor - Parameter specifying how much the image size is reduced at each image scale. to retain it. cvHaarDetectObjects. It is not used for a new cascade.
• #### detectMultiScale2

public void detectMultiScale2​(Mat image,
MatOfRect objects,
MatOfInt numDetections)
Parameters:
image - Matrix of the type CV_8U containing an image where objects are detected.
objects - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
numDetections - 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 to form the object. to retain it. cvHaarDetectObjects. It is not used for a new cascade.
• #### detectMultiScale3

public void detectMultiScale3​(Mat image,
MatOfRect objects,
MatOfInt rejectLevels,
MatOfDouble levelWeights,
double scaleFactor,
int minNeighbors,
int flags,
Size minSize,
Size maxSize,
boolean outputRejectLevels)
This function allows you to retrieve the final stage decision certainty of classification. For this, one needs to set outputRejectLevels on true and provide the rejectLevels and levelWeights parameter. For each resulting detection, levelWeights will then contain the certainty of classification at the final stage. This value can then be used to separate strong from weaker classifications. A code sample on how to use it efficiently can be found below:  Mat img; vector<double> weights; vector<int> levels; vector<Rect> detections; CascadeClassifier model("/path/to/your/model.xml"); model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; 
Parameters:
image - automatically generated
objects - automatically generated
rejectLevels - automatically generated
levelWeights - automatically generated
scaleFactor - automatically generated
minNeighbors - automatically generated
flags - automatically generated
minSize - automatically generated
maxSize - automatically generated
outputRejectLevels - automatically generated
• #### detectMultiScale3

public void detectMultiScale3​(Mat image,
MatOfRect objects,
MatOfInt rejectLevels,
MatOfDouble levelWeights,
double scaleFactor,
int minNeighbors,
int flags,
Size minSize,
Size maxSize)
This function allows you to retrieve the final stage decision certainty of classification. For this, one needs to set outputRejectLevels on true and provide the rejectLevels and levelWeights parameter. For each resulting detection, levelWeights will then contain the certainty of classification at the final stage. This value can then be used to separate strong from weaker classifications. A code sample on how to use it efficiently can be found below:  Mat img; vector<double> weights; vector<int> levels; vector<Rect> detections; CascadeClassifier model("/path/to/your/model.xml"); model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; 
Parameters:
image - automatically generated
objects - automatically generated
rejectLevels - automatically generated
levelWeights - automatically generated
scaleFactor - automatically generated
minNeighbors - automatically generated
flags - automatically generated
minSize - automatically generated
maxSize - automatically generated
• #### detectMultiScale3

public void detectMultiScale3​(Mat image,
MatOfRect objects,
MatOfInt rejectLevels,
MatOfDouble levelWeights,
double scaleFactor,
int minNeighbors,
int flags,
Size minSize)
This function allows you to retrieve the final stage decision certainty of classification. For this, one needs to set outputRejectLevels on true and provide the rejectLevels and levelWeights parameter. For each resulting detection, levelWeights will then contain the certainty of classification at the final stage. This value can then be used to separate strong from weaker classifications. A code sample on how to use it efficiently can be found below:  Mat img; vector<double> weights; vector<int> levels; vector<Rect> detections; CascadeClassifier model("/path/to/your/model.xml"); model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; 
Parameters:
image - automatically generated
objects - automatically generated
rejectLevels - automatically generated
levelWeights - automatically generated
scaleFactor - automatically generated
minNeighbors - automatically generated
flags - automatically generated
minSize - automatically generated
• #### detectMultiScale3

public void detectMultiScale3​(Mat image,
MatOfRect objects,
MatOfInt rejectLevels,
MatOfDouble levelWeights,
double scaleFactor,
int minNeighbors,
int flags)
This function allows you to retrieve the final stage decision certainty of classification. For this, one needs to set outputRejectLevels on true and provide the rejectLevels and levelWeights parameter. For each resulting detection, levelWeights will then contain the certainty of classification at the final stage. This value can then be used to separate strong from weaker classifications. A code sample on how to use it efficiently can be found below:  Mat img; vector<double> weights; vector<int> levels; vector<Rect> detections; CascadeClassifier model("/path/to/your/model.xml"); model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; 
Parameters:
image - automatically generated
objects - automatically generated
rejectLevels - automatically generated
levelWeights - automatically generated
scaleFactor - automatically generated
minNeighbors - automatically generated
flags - automatically generated
• #### detectMultiScale3

public void detectMultiScale3​(Mat image,
MatOfRect objects,
MatOfInt rejectLevels,
MatOfDouble levelWeights,
double scaleFactor,
int minNeighbors)
This function allows you to retrieve the final stage decision certainty of classification. For this, one needs to set outputRejectLevels on true and provide the rejectLevels and levelWeights parameter. For each resulting detection, levelWeights will then contain the certainty of classification at the final stage. This value can then be used to separate strong from weaker classifications. A code sample on how to use it efficiently can be found below:  Mat img; vector<double> weights; vector<int> levels; vector<Rect> detections; CascadeClassifier model("/path/to/your/model.xml"); model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; 
Parameters:
image - automatically generated
objects - automatically generated
rejectLevels - automatically generated
levelWeights - automatically generated
scaleFactor - automatically generated
minNeighbors - automatically generated
• #### detectMultiScale3

public void detectMultiScale3​(Mat image,
MatOfRect objects,
MatOfInt rejectLevels,
MatOfDouble levelWeights,
double scaleFactor)
This function allows you to retrieve the final stage decision certainty of classification. For this, one needs to set outputRejectLevels on true and provide the rejectLevels and levelWeights parameter. For each resulting detection, levelWeights will then contain the certainty of classification at the final stage. This value can then be used to separate strong from weaker classifications. A code sample on how to use it efficiently can be found below:  Mat img; vector<double> weights; vector<int> levels; vector<Rect> detections; CascadeClassifier model("/path/to/your/model.xml"); model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; 
Parameters:
image - automatically generated
objects - automatically generated
rejectLevels - automatically generated
levelWeights - automatically generated
scaleFactor - automatically generated
• #### detectMultiScale3

public void detectMultiScale3​(Mat image,
MatOfRect objects,
MatOfInt rejectLevels,
MatOfDouble levelWeights)
This function allows you to retrieve the final stage decision certainty of classification. For this, one needs to set outputRejectLevels on true and provide the rejectLevels and levelWeights parameter. For each resulting detection, levelWeights will then contain the certainty of classification at the final stage. This value can then be used to separate strong from weaker classifications. A code sample on how to use it efficiently can be found below:  Mat img; vector<double> weights; vector<int> levels; vector<Rect> detections; CascadeClassifier model("/path/to/your/model.xml"); model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; 
Parameters:
image - automatically generated
objects - automatically generated
rejectLevels - automatically generated
levelWeights - automatically generated

public boolean isOldFormatCascade()
• #### getOriginalWindowSize

public Size getOriginalWindowSize()
• #### getFeatureType

public int getFeatureType()
• #### convert

public static boolean convert​(java.lang.String oldcascade,
java.lang.String newcascade)
• #### finalize

protected void finalize()
throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable