Face detection and processing
Functions for face detection, counting, and blurring, suitable for face detection and privacy protection scenarios.
The functions in this topic are provided by the Python multimodal function library (VVR 11.8+). Load the module at the beginning of the SQL job before use:
LOAD MODULE python;
USE MODULES python, core;
For complete examples and the IMAGE type, see Image function overview.
Function summary
|
Function |
Description |
|
Detect faces and return bounding boxes |
|
|
Count faces in an image |
|
|
Blur detected face regions |
IMAGE_FACE_DETECT
Detects faces and returns bounding boxes.
IMAGE_FACE_DETECT(image_input [, cv_classifier [, min_neighbors [, scale_factor
[, min_size [, max_size]]]]])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
cv_classifier |
|
|
OpenCV cascade classifier XML file. |
|
min_neighbors |
|
|
Minimum number of neighbors required to retain a detection window. |
|
scale_factor |
|
|
Scale factor for multi-scale detection. |
|
min_size |
|
|
Minimum face size |
|
max_size |
|
|
Maximum face size |
Return type: ARRAY<ROW<x INT, y INT, w INT, h INT, confidence DOUBLE>>
Each element in the returned array represents a detected face bounding box:
|
Field |
Description |
|
|
Top-left coordinates of the bounding box, in pixels. |
|
|
Width and height of the bounding box, in pixels. |
|
|
Detection confidence. The current face detector does not return per-box probabilities, so this field is |
SELECT CARDINALITY(IMAGE_FACE_DETECT(img)) AS face_count FROM images;
IMAGE_FACE_COUNT
Counts the number of faces in an image. Parameters are the same as IMAGE_FACE_DETECT.
IMAGE_FACE_COUNT(image_input [, cv_classifier [, min_neighbors [, scale_factor
[, min_size [, max_size]]]]])
Return type: INT
NULL when the input is NULL. Returns 0 when no face is detected in a valid image.
SELECT IMAGE_FACE_COUNT(img, 'haarcascade_frontalface_alt.xml', 3, 1.1)
FROM images;
IMAGE_FACE_BLUR
Detects faces and blurs the detected face regions.
IMAGE_FACE_BLUR(image_input [, cv_classifier [, blur_type [, radius
[, min_neighbors [, scale_factor [, min_size [, max_size]]]]]]])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
cv_classifier |
|
|
OpenCV cascade classifier XML file. |
|
blur_type |
|
|
Blur algorithm. Supported values: |
|
radius |
|
|
Blur radius. |
|
min_neighbors |
|
|
Minimum number of neighbors required to retain a detection window. |
|
scale_factor |
|
|
Scale factor for multi-scale detection. |
|
min_size |
|
|
Minimum face size |
|
max_size |
|
|
Maximum face size |
Return type: IMAGE
The returned image preserves the original content and replaces the detected face regions with blurred regions.
SELECT IMAGE_ENCODE(IMAGE_FACE_BLUR(img, 'haarcascade_frontalface_alt.xml', 'gaussian', 15), 'JPEG')
FROM images;