@Opaque @Properties(inherit=opencv_objdetect.class) public class CvHaarClassifierCascade extends Pointer
\{ \defgroup objdetect_cascade_classifier Cascade Classifier for Object Detection
The object detector described below has been initially proposed by Paul Viola \cite Viola01 and improved by Rainer Lienhart \cite Lienhart02 .
First, a classifier (namely a *cascade of boosted classifiers working with haar-like features*) is trained with a few hundred sample views of a particular object (i.e., a face or a car), called positive examples, that are scaled to the same size (say, 20x20), and negative examples - arbitrary images of the same size.
After a classifier is trained, it can be applied to a region of interest (of the same size as used during the training) in an input image. The classifier outputs a "1" if the region is likely to show the object (i.e., face/car), and "0" otherwise. To search for the object in the whole image one can move the search window across the image and check every location using the classifier. The classifier is designed so that it can be easily "resized" in order to be able to find the objects of interest at different sizes, which is more efficient than resizing the image itself. So, to find an object of an unknown size in the image the scan procedure should be done several times at different scales.
The word "cascade" in the classifier name means that the resultant classifier consists of several simpler classifiers (*stages*) that are applied subsequently to a region of interest until at some stage the candidate is rejected or all the stages are passed. The word "boosted" means that the classifiers at every stage of the cascade are complex themselves and they are built out of basic classifiers using one of four different boosting techniques (weighted voting). Currently Discrete Adaboost, Real Adaboost, Gentle Adaboost and Logitboost are supported. The basic classifiers are decision-tree classifiers with at least 2 leaves. Haar-like features are the input to the basic classifiers, and are calculated as described below. The current algorithm uses the following Haar-like features:

The feature used in a particular classifier is specified by its shape (1a, 2b etc.), position within the region of interest and the scale (this scale is not the same as the scale used at the detection stage, though these two scales are multiplied). For example, in the case of the third line feature (2c) the response is calculated as the difference between the sum of image pixels under the rectangle covering the whole feature (including the two white stripes and the black stripe in the middle) and the sum of the image pixels under the black stripe multiplied by 3 in order to compensate for the differences in the size of areas. The sums of pixel values over a rectangular regions are calculated rapidly using integral images (see below and the integral description).
Check \ref tutorial_cascade_classifier "the corresponding tutorial" for more details.
The following reference is for the detection part only. There is a separate application called opencv_traincascade that can train a cascade of boosted classifiers from a set of samples.
\note In the new C++ interface it is also possible to use LBP (local binary pattern) features in
addition to Haar-like features. .. [Viola01] Paul Viola and Michael J. Jones. Rapid Object Detection
using a Boosted Cascade of Simple Features. IEEE CVPR, 2001. The paper is available online at
\defgroup objdetect_hog HOG (Histogram of Oriented Gradients) descriptor and object detector
\defgroup objdetect_barcode Barcode detection and decoding
\defgroup objdetect_qrcode QRCode detection and encoding
\defgroup objdetect_dnn_face DNN-based face detection and recognition
Check \ref tutorial_dnn_face "the corresponding tutorial" for more details.
\defgroup objdetect_common Common functions and classes
\defgroup objdetect_aruco ArUco markers and boards detection for robust camera pose estimation
\{
ArUco Marker Detection
Square fiducial markers (also known as Augmented Reality Markers) are useful for easy,
fast and robust camera pose estimation.
The main functionality of ArucoDetector class is detection of markers in an image. If the markers are grouped
as a board, then you can try to recover the missing markers with ArucoDetector::refineDetectedMarkers().
ArUco markers can also be used for advanced chessboard corner finding. To do this, group the markers in the
CharucoBoard and find the corners of the chessboard with the CharucoDetector::detectBoard().
The implementation is based on the ArUco Library by R. Muñoz-Salinas and S. Garrido-Jurado \cite Aruco2014.
Markers can also be detected based on the AprilTag 2 \cite wang2016iros fiducial detection method.
Aruco2014
This code has been originally developed by Sergio Garrido-Jurado as a project
for Google Summer of Code 2015 (GSoC 15).
\warning In OpenCV, the order of the returned corners locations for the AprilTag family is not aligned with the ArUco one.\n
Note that this order is also different from the convention adopted by the official [AprilTag library](https://github.com/AprilRobotics/apriltag/).
 { width=80% }
An overview of the supported ArUco markers family is visible in the following image:
 { width=80% }
An overview of the supported AprilTag markers family is visible in the following image:
 { width=80% }
\note The generated images (in the above picture) using \ref aruco::generateImageMarker for the AprilTag markers have been
rotated by 180 degree in order to match the official AprilTag images.
When using the \ref aruco::generateImageMarker function, it will output by default a different image from the official AprilTag convention,
see the [AprilRobotics/apriltag-imgs](https://github.com/AprilRobotics/apriltag-imgs) repository.
This is the reason why you see a different corners order between ArUco and AprilTag in the above image.
For the ArUco marker family, the recommended family is the DICT_ARUCO_MIP_36h12 one, [see](https://stackoverflow.com/a/51511558).
In general, a smaller marker family (e.g. {@code 4x4} vs {@code 6x6}) should give you a better detection rate with respect to the camera distance,
at the expense of having more probability to have issues with false detection or marker id decoding error.
The number of marker ids in a family is also something to take into account with respect to the application use case and the ability
to correct wrong bits during the marker id decoding process.
You can download some pregenerated MIP_36h12 ArUco marker images from:
- https://sourceforge.net/projects/aruco/files/
- or use the {@code samples/cpp/tutorial_code/objectDetection/create_marker.cpp} sample to generate the marker image for your
desired marker family (which uses the \ref aruco::generateImageMarker function)
For the AprilTag family, you can find some pregenerated marker images in the
[AprilRobotics/apriltag-imgs](https://github.com/AprilRobotics/apriltag-imgs) repository.
\note For accurate corners location extraction, a white border (to have a strong gradient between white and black transition) around the marker is important.
This is necessary to precisely extract the marker contour in difficult conditions such as bad illumination, confusing color background, etc.
There are multiple parameters which can be tweaked to improve the marker detection rate or to be adapted to your use case (e.g. image resolution).
Please refer to the:
- \ref aruco::DetectorParameters
- "Detector Parameters" section in the \ref tutorial_aruco_detection tutorial or in the \ref tutorial_aruco_faq page
- [ArUco Library Documentation](https://drive.google.com/file/d/1OiavRVYVJ-WH88sQg1LUsh8CuJZUQyrX) for additional information from the ArUco library
The corner refinement method can be changed according to the \ref aruco::CornerRefineMethod to improve the corners location accuracy
at the expense of more computation time.
To estimate the marker pose with respect to the camera frame, we recommend you to look at the following sources of information:
- \ref tutorial_aruco_detection for a tutorial about ArUco markers detection
- \ref calib3d for some theoretical background about the pinhole camera model and the \ref calib3d_solvePnP page
- \ref solvePnP, \ref solvePnPGeneric, \ref solveP3P for the relevant pose estimation methods
\}
\}
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter| Constructor and Description |
|---|
CvHaarClassifierCascade()
Empty constructor.
|
CvHaarClassifierCascade(Pointer p)
Pointer cast constructor.
|
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, getDirectBufferAddress, getPointer, getPointer, getPointer, getPointer, hashCode, interruptDeallocatorThread, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetAddress, offsetof, offsetof, parseBytes, physicalBytes, physicalBytesInaccurate, position, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, trimMemory, withDeallocator, zeropublic CvHaarClassifierCascade()
super((Pointer)null).public CvHaarClassifierCascade(Pointer p)
Pointer(Pointer).Copyright © 2026. All rights reserved.