CascadeClassifier
import { CascadeClassifier } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods.
example: samples/facedetect.cpp This program demonstrates usage of the Cascade classifier class \image html Cascade_Classifier_Tutorial_Result_Haar.jpg "Sample screenshot" width=321 height=254 Cascade classifier class for object detection.
Constructors and members
static new
Loads a classifier from a file.
new(filename: EmbindString): CascadeClassifier;filenameName of the file from which the classifier is loaded.
The CascadeClassifier result.
static convert
Convert a legacy Haar cascade file to the newer cascade serialization format in the virtual filesystem.
convert(oldcascade: EmbindString, newcascade: EmbindString): boolean;oldcascadeoldcascade argument (EmbindString).
newcascadenewcascade argument (EmbindString).
The boolean result.
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
empty
Checks whether the classifier has been loaded.
empty(): boolean;The boolean result.
load
Loads a classifier from a file.
load(filename: EmbindString): boolean;filenameName 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.
The boolean result.
read
Reads a classifier from a FileStorage node.
Note: The file may contain a new cascade classifier (trained by the traincascade application) only.
read(node: FileNode): boolean;nodenode argument (FileNode).
The boolean result.
detectMultiScale
Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
detectMultiScale(image: Mat, objects: RectVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size, maxSize: Size): void;6 available overloads
detectMultiScale(image: Mat, objects: RectVector): void;detectMultiScale(image: Mat, objects: RectVector, scaleFactor: number): void;detectMultiScale(image: Mat, objects: RectVector, scaleFactor: number, minNeighbors: number): void;detectMultiScale(image: Mat, objects: RectVector, scaleFactor: number, minNeighbors: number, flags: number): void;detectMultiScale(image: Mat, objects: RectVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size): void;detectMultiScale(image: Mat, objects: RectVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size, maxSize: Size): void;imageMatrix of the type CV_8U containing an image where objects are detected.
objectsOutput destination, filled by the native operation. Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
scaleFactorParameter specifying how much the image size is reduced at each image scale.
minNeighborsParameter specifying how many neighbors each candidate rectangle should have to retain it.
flagsParameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
minSizeMinimum possible object size. Objects smaller than that are ignored.
maxSizeMaximum possible object size. Objects larger than that are ignored. If
maxSize == minSizemodel is evaluated on single scale.
detectMultiScale2
Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
detectMultiScale2(image: Mat, objects: RectVector, numDetections: IntVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size, maxSize: Size): void;6 available overloads
detectMultiScale2(image: Mat, objects: RectVector, numDetections: IntVector): void;detectMultiScale2(image: Mat, objects: RectVector, numDetections: IntVector, scaleFactor: number): void;detectMultiScale2(image: Mat, objects: RectVector, numDetections: IntVector, scaleFactor: number, minNeighbors: number): void;detectMultiScale2(image: Mat, objects: RectVector, numDetections: IntVector, scaleFactor: number, minNeighbors: number, flags: number): void;detectMultiScale2(image: Mat, objects: RectVector, numDetections: IntVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size): void;detectMultiScale2(image: Mat, objects: RectVector, numDetections: IntVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size, maxSize: Size): void;imageMatrix of the type CV_8U containing an image where objects are detected.
objectsOutput destination, filled by the native operation. Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
numDetectionsOutput destination, filled by the native operation. 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.
scaleFactorParameter specifying how much the image size is reduced at each image scale.
minNeighborsParameter specifying how many neighbors each candidate rectangle should have to retain it.
flagsParameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
minSizeMinimum possible object size. Objects smaller than that are ignored.
maxSizeMaximum possible object size. Objects larger than that are ignored. If
maxSize == minSizemodel is evaluated on single scale.
detectMultiScale3
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;
detectMultiScale3(image: Mat, objects: RectVector, rejectLevels: IntVector, levelWeights: DoubleVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size, maxSize: Size, outputRejectLevels: boolean): void;7 available overloads
detectMultiScale3(image: Mat, objects: RectVector, rejectLevels: IntVector, levelWeights: DoubleVector): void;detectMultiScale3(image: Mat, objects: RectVector, rejectLevels: IntVector, levelWeights: DoubleVector, scaleFactor: number): void;detectMultiScale3(image: Mat, objects: RectVector, rejectLevels: IntVector, levelWeights: DoubleVector, scaleFactor: number, minNeighbors: number): void;detectMultiScale3(image: Mat, objects: RectVector, rejectLevels: IntVector, levelWeights: DoubleVector, scaleFactor: number, minNeighbors: number, flags: number): void;detectMultiScale3(image: Mat, objects: RectVector, rejectLevels: IntVector, levelWeights: DoubleVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size): void;detectMultiScale3(image: Mat, objects: RectVector, rejectLevels: IntVector, levelWeights: DoubleVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size, maxSize: Size): void;detectMultiScale3(image: Mat, objects: RectVector, rejectLevels: IntVector, levelWeights: DoubleVector, scaleFactor: number, minNeighbors: number, flags: number, minSize: Size, maxSize: Size, outputRejectLevels: boolean): void;imageimage argument (Mat).
objectsOutput destination, filled by the native operation. objects argument (RectVector).
rejectLevelsOutput destination, filled by the native operation. reject levels argument (IntVector).
levelWeightsOutput destination, filled by the native operation. level weights argument (DoubleVector).
scaleFactorscale factor argument (number).
minNeighborsmin neighbors argument (number).
flagsflags argument (number).
minSizemin size argument (Size).
maxSizemax size argument (Size).
outputRejectLevelsoutput reject levels argument (boolean).
isOldFormatCascade
Return whether the loaded classifier uses the legacy Haar cascade format.
isOldFormatCascade(): boolean;The boolean result.
getOriginalWindowSize
Return the original window size configured on this CascadeClassifier object.
getOriginalWindowSize(): Size;The Size result.
getFeatureType
Return the feature type configured on this CascadeClassifier object.
getFeatureType(): number;The number result.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.