[IMPORTANT: The user has invoked the "face-detection-blur" skill, indicating they want you to follow its instructions. The full skill content is loaded below.]
---
name: face-detection-blur
description: Detect faces in an image using OpenCV (Haar cascades or DNN) and apply a Gaussian blur to each face.
category: software-development
author: Hermes Agent
version: 1.1
metadata:
hermes:
tags: [face-detection, opencv, blur, privacy, computer-vision]
related_skills: [hermes-user-skills]
---
# Face Detection & Blur Skill
This skill provides a reproducible way to detect faces in a JPEG/PNG image and blur them using OpenCV. It first attempts Haar cascade detection (fast, lightweight) and falls back to a deep‑learning based DNN detector for better accuracy on challenging poses or lighting.
## When to Use
- You need to obscure faces in photos for privacy before sharing.
- You want a quick, scriptable solution without relying on external APIs.
- You are comfortable running a small Python script and installing OpenCV via pip.
## Prerequisites
- Python 3.6+ (the Hermes agent uses Python 3.11).
- Access to
pip (the Hermes virtualenv is at
/usr/local/lib/hermes-agent/venv/bin/python3).
- Network access to download the Haar cascade XML (~200 KB) and, optionally, the DNN model files (~5 MB).
## Installation Steps
1. **Activate the Hermes venv (if not already active).**
``
bash
source /usr/local/lib/hermes-agent/venv/bin/activate
`
2. **Install OpenCV (opencv-python) and numpy.**
`
bash
pip install opencv-python numpy
`
3. **Download the pre‑trained Haar cascade for frontal faces.**
`
bash
mkdir -p ~/face_detect_resources
cd ~/face_detect_resources
wget -O haarcascade_frontalface_default.xml \
https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml
`
4. **(Optional) Download the DNN face detector model for higher accuracy.**
`
bash
mkdir -p ~/face_detect_dnn
cd ~/face_detect_dnn
wget -O deploy.prototxt \
https://raw.githubusercontent.com/opencv/opencv/master/samples/dnn/face_detector/deploy.prototxt
wget -O res10_300x300_ssd_iter_140000.caffemodel \
https://github.com/opencv/opencv_3rdparty/raw/dnn_samples_face_detector_20170830/res10_300x300_ssd_iter_140000.caffemodel
`
## Usage
The skill ships with two ready‑to‑run scripts:
- **scripts/blur_faces.py
** – Haar‑cascade based detection (default).
- **scripts/blur_faces_dnn.py
** – DNN‑based detection (more accurate, slightly slower).
### Haar‑cascade script
`
bash
python scripts/blur_faces.py [blur_ksize]
`
* blur_ksize
– optional odd integer for Gaussian blur kernel; if omitted or ≤0, the script chooses a size proportional to the face width.
### DNN script
`
bash
python scripts/blur_faces_dnn.py [conf_threshold]
`
* conf_threshold
– minimum confidence for a detection to be kept (default 0.5). Lower values increase recall but may add false positives.
Both scripts will:
1. Load the input image.
2. Detect faces (using the selected method).
3. Apply a Gaussian blur to each detected face region (kernel size proportional to face size).
4. Save the result to .
If no faces are detected, the original image is copied unchanged.
## Verification
- Run either script on a test image containing faces.
- Visually inspect the output: faces should be blurred while the rest of the scene stays sharp.
- Confirm the file size is similar to the original (blur does not change dimensions).
## Tips & Pitfalls
- **Haar cascades** work best on frontal, well‑lit faces. Profile views, extreme angles, or low lighting may be missed.
- **DNN model** is more robust to pose and lighting but requires the extra ~5 MB model files.
- **Multiple faces** are processed independently; overlapping detections are handled sequentially.
- **Performance**: On a typical VPS CPU, a 2 MP image takes < 1 second with Haar cascades and ~1‑2 seconds with the DNN model.
- **Cleanup**: The cascade and model directories can be reused; delete them only if you need to free space.
- **Alternative models**: For even higher accuracy, consider OpenCV’s newer face detection models (e.g., YuNet) – swap the prototxt/model files accordingly.
## Safety & Legal
- Only process images you have the right to modify.
- Blurring faces is a privacy‑preserving transformation; ensure it meets your jurisdiction’s requirements for anonymization.
---
*End of skill.*
[Skill directory: /root/.hermes/skills/face-detection-blur]
Resolve any relative paths in this skill (e.g. scripts/foo.js, templates/config.yaml) against that directory, then run them with the terminal tool using the absolute path.
[This skill has supporting files:]
- scripts/blur_faces.py -> /root/.hermes/skills/face-detection-blur/scripts/blur_faces.py
- scripts/blur_faces_dnn.py -> /root/.hermes/skills/face-detection-blur/scripts/blur_faces_dnn.py
Load any of these with skill_view(name="face-detection-blur", file_path=""), or run scripts directly by absolute path (e.g. node /root/.hermes/skills/face-detection-blur/scripts/foo.js`).