DEV Community

Nariaki Wada
Nariaki Wada

Posted on

High-Speed Face Detection and Scale Invariance with OpenCV YuNet

High-Speed Face Detection and Scale Invariance with OpenCV YuNet

Hello, everyone.

Have you ever been startled by a strange pattern on the ceiling that looked like a human face? I have, quite often.

Today, I verified the overwhelming inference speed and how detection accuracy changes depending on the image resolution (scale) using the YuNet face detection model available in OpenCV Zoo.

What we are verifying

Using the YuNet INT8 quantized model (ONNX) published in OpenCV Zoo, we verify the following two points:

  • Inference speed per execution on a 1280x720 image
  • Changes in the number of detected faces and scores when the same image is resized from 0.25x to 2.0x

Target lab: kiarina/labs/2026/07/08/yunet-face-detection

Reproducing the environment

You can build the verification environment and run it yourself using the commands below. mise and uv are required.

git clone --depth 1 --filter=blob:none --sparse \
  https://github.com/kiarina/labs.git
cd labs
git sparse-checkout set .gitignore .mise/tasks Makefile mise.toml 2026/07/08/yunet-face-detection
mise -C 2026/07/08/yunet-face-detection run
Enter fullscreen mode Exit fullscreen mode

Image used for verification

For this test, we used the following image (1280x720) containing a large number of people.

Multi-face image used for verification

Verification results and highlights

The results executed on a Mac Studio (Apple M4 Max) are as follows.

--- Inference Speed Benchmark (Iterations: 100) ---
Average time: 9.21 ms
Min time:     8.03 ms
Max time:     10.47 ms
Std dev:      0.55 ms

--- Scale Variance Experiment ---
 Scale |    Resolution |  Faces | Max Score | Min Score
-------------------------------------------------------
  0.25 |       320x180 |      6 |     0.871 |     0.638
  0.50 |       640x360 |     26 |     0.910 |     0.611
  0.75 |       960x540 |     32 |     0.920 |     0.622
  1.00 |      1280x720 |     38 |     0.930 |     0.630
  1.50 |     1920x1080 |     43 |     0.937 |     0.652
  2.00 |     2560x1440 |     52 |     0.939 |     0.605
Enter fullscreen mode Exit fullscreen mode

Detection results (Scale 1.0)

Interpretation of results

The technical data is shown above, but here is a simple summary:

  1. Incredibly fast
    It took an average of only 0.009 seconds to find faces in a single image. It's fast enough for real-time video processing with plenty of margin.

  2. Larger images reveal smaller faces in the back
    When the image was scaled down (0.25x), it only found 6 large faces in the front. Conversely, when the image was scaled up (2.0x), it was able to find 52 faces, including the small and blurry ones far in the back.

  3. Face detection scores
    As the image got larger, the confidence (score) for clearly visible faces increased, but the newly found "small, blurry faces" maintained low scores (around 0.6).

Thoughts after verification

YuNet is extremely lightweight and runs smoothly without needing a dedicated graphics card, which is wonderful. However, I found that the ability to detect a face depends heavily on its "size" within the image.

If you want to find small faces far away, it seems necessary to devise strategies like enlarging the entire image beforehand before passing it to YuNet. I felt it is an excellent model for easy-to-integrate face detection.

Top comments (0)