DEV Community

TildAlice
TildAlice

Posted on • Originally published at tildalice.io

OpenCV Face Blur: 3 Mistakes That Kill Real-Time FPS

The 15 FPS Problem Everyone Hits First

You copy the basic OpenCV face detection example, add cv2.GaussianBlur() to anonymize faces, and your webcam drops from 30 FPS to 15. Sometimes 8. The Haar cascade tutorial worked fine in the demo, so what broke?

The answer: you're blurring the entire frame, not just the face regions. And you're probably using cv2.CascadeClassifier with default parameters that scan every possible face size at every frame.

Here's what actually happens when you run the naive approach on a 1280x720 webcam feed.

Conceptual portrait with laser scanning for facial recognition on plain black background.

Photo by cottonbro studio on Pexels

Mistake 1: Blurring the Wrong Numpy Slice

Most beginners write something like this:


python
import cv2
import numpy as np

cap = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier(
    cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
)

while True:
    ret, frame = cap.read()
    if not ret:
        break

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    for (x, y, w, h) in faces:

---

*Continue reading the full article on [TildAlice](https://tildalice.io/opencv-face-blur-real-time-fps-fixes/)*
Enter fullscreen mode Exit fullscreen mode

Top comments (0)