FaceDetectorYN
import { FaceDetectorYN } 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.
DNN-based face detector
model download link: https://github.com/opencv/opencv_zoo/tree/master/models/face_detection_yunet
Constructors and members
static create
Creates an instance of face detector class with given parameters
create(model: EmbindString, config: EmbindString, input_size: Size, score_threshold: number, nms_threshold: number, top_k: number, backend_id: number, target_id: number): FaceDetectorYN | null;6 available overloads
create(model: EmbindString, config: EmbindString, input_size: Size): FaceDetectorYN | null;create(model: EmbindString, config: EmbindString, input_size: Size, score_threshold: number): FaceDetectorYN | null;create(model: EmbindString, config: EmbindString, input_size: Size, score_threshold: number, nms_threshold: number): FaceDetectorYN | null;create(model: EmbindString, config: EmbindString, input_size: Size, score_threshold: number, nms_threshold: number, top_k: number): FaceDetectorYN | null;create(model: EmbindString, config: EmbindString, input_size: Size, score_threshold: number, nms_threshold: number, top_k: number, backend_id: number): FaceDetectorYN | null;create(model: EmbindString, config: EmbindString, input_size: Size, score_threshold: number, nms_threshold: number, top_k: number, backend_id: number, target_id: number): FaceDetectorYN | null;modelthe path to the requested model
configthe path to the config file for compatibility, which is not requested for ONNX models
input_sizethe size of the input image
score_thresholdthe threshold to filter out bounding boxes of score smaller than the given value
nms_thresholdthe threshold to suppress bounding boxes of IoU bigger than the given value
top_kkeep top K bboxes before NMS
backend_idthe id of backend
target_idthe id of target device
The FaceDetectorYN | null result.
static create1
Creates an instance of face detector class with given parameters
create1(framework: EmbindString, bufferModel: ucharVector, bufferConfig: ucharVector, input_size: Size, score_threshold: number, nms_threshold: number, top_k: number, backend_id: number, target_id: number): FaceDetectorYN | null;6 available overloads
create1(framework: EmbindString, bufferModel: ucharVector, bufferConfig: ucharVector, input_size: Size): FaceDetectorYN | null;create1(framework: EmbindString, bufferModel: ucharVector, bufferConfig: ucharVector, input_size: Size, score_threshold: number): FaceDetectorYN | null;create1(framework: EmbindString, bufferModel: ucharVector, bufferConfig: ucharVector, input_size: Size, score_threshold: number, nms_threshold: number): FaceDetectorYN | null;create1(framework: EmbindString, bufferModel: ucharVector, bufferConfig: ucharVector, input_size: Size, score_threshold: number, nms_threshold: number, top_k: number): FaceDetectorYN | null;create1(framework: EmbindString, bufferModel: ucharVector, bufferConfig: ucharVector, input_size: Size, score_threshold: number, nms_threshold: number, top_k: number, backend_id: number): FaceDetectorYN | null;create1(framework: EmbindString, bufferModel: ucharVector, bufferConfig: ucharVector, input_size: Size, score_threshold: number, nms_threshold: number, top_k: number, backend_id: number, target_id: number): FaceDetectorYN | null;frameworkName of origin framework
bufferModelA buffer with a content of binary file with weights
bufferConfigA buffer with a content of text file contains network configuration
input_sizethe size of the input image
score_thresholdthe threshold to filter out bounding boxes of score smaller than the given value
nms_thresholdthe threshold to suppress bounding boxes of IoU bigger than the given value
top_kkeep top K bboxes before NMS
backend_idthe id of backend
target_idthe id of target device
The FaceDetectorYN | null 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.
setInputSize
Set the size for the network input, which overwrites the input size of creating model. Call this method when the size of input image does not match the input size when creating model
setInputSize(input_size: Size): void;input_sizethe size of the input image
getInputSize
Read the input size.
Set the size for the network input, which overwrites the input size of creating model. Call this method when the size of input image does not match the input size when creating model
getInputSize(): Size;The Size result.
setScoreThreshold
Set the score threshold to filter out bounding boxes of score less than the given value
setScoreThreshold(score_threshold: number): void;score_thresholdthreshold for filtering out bounding boxes
getScoreThreshold
Read the score threshold.
Set the score threshold to filter out bounding boxes of score less than the given value
getScoreThreshold(): number;The number result.
setNMSThreshold
Set the Non-maximum-suppression threshold to suppress bounding boxes that have IoU greater than the given value
setNMSThreshold(nms_threshold: number): void;nms_thresholdthreshold for NMS operation
getNMSThreshold
Read the nmsthreshold.
Set the Non-maximum-suppression threshold to suppress bounding boxes that have IoU greater than the given value
getNMSThreshold(): number;The number result.
setTopK
Set the number of bounding boxes preserved before NMS
setTopK(top_k: number): void;top_kthe number of bounding boxes to preserve from top rank based on score
getTopK
Read the top k.
Set the number of bounding boxes preserved before NMS
getTopK(): number;The number result.
detect
Detects faces in the input image. Following is an example output.

detect(image: Mat, faces: Mat): number;imagean image to detect
facesOutput destination, filled by the native operation. detection results stored in a 2D cv::Mat of shape [num_faces, 15]
- 0-1: x, y of bbox top left corner
- 2-3: width, height of bbox
- 4-5: x, y of right eye (blue point in the example image)
- 6-7: x, y of left eye (red point in the example image)
- 8-9: x, y of nose tip (green point in the example image)
- 10-11: x, y of right corner of mouth (pink point in the example image)
- 12-13: x, y of left corner of mouth (yellow point in the example image)
- 14: face score
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.