pyflink.multimodal.operators.image_face_count#
- image_face_count(*columns, cv_classifier='haarcascade_frontalface_alt.xml', min_neighbors=3, scale_factor=1.1, min_size=None, max_size=None, concurrency=None)[source]#
Create a face count UDF (OpenCV Haar Cascade-based).
Requires
pip install opencv-python-headless. This is a scalar UDF that returns the number of detected faces as an integer.- Parameters
*columns – Optional image column(s). When provided, the UDF is applied directly instead of returning a factory.
cv_classifier – OpenCV Haar cascade XML filename. Must be a bare filename without path separators. Default
"haarcascade_frontalface_alt.xml".min_neighbors – OpenCV
detectMultiScaleminNeighborsvalue. Higher values reduce false positives but may miss faces. Default3.scale_factor – Image pyramid scale factor for multi-scale detection. Default
1.1.min_size – Minimum face size as
(width, height)tuple in pixels. Detections smaller than this are ignored.None(default) uses OpenCV’s built-in minimum.max_size – Maximum face size as
(width, height)tuple in pixels. Detections larger than this are ignored.None(default) imposes no upper limit.concurrency – UDF concurrency.
Noneuses the framework default.
- Returns
A UDF that returns the number of detected faces as an integer, or
Nonefor null input.Nonemeans the input itself is null;0means a valid image was processed and no faces were detected.- Raises
ValueError – If detection parameters are invalid.
Usage:
>>> # As a reusable variable >>> count = image_face_count(min_neighbors=3) >>> df = df.with_column("face_count", count(col("img"))) >>> >>> # Inline >>> df = df.with_column("face_count", image_face_count(col("img")))