fix(blur-faces): switch from MediaPipe to OpenCV and auto-orient images

Fix face detection failure caused by MediaPipe 0.10.33 removing the
mp.solutions API. Replace with OpenCV Haar cascade which works reliably
in headless Docker. Add autoOrient() call before detection to handle
EXIF-rotated phone photos. Remove technical jargon from UI.
This commit is contained in:
Siddharth Kumar Sah
2026-03-26 16:01:56 +08:00
parent 8ee4d7b2fb
commit f15102c632
3 changed files with 58 additions and 50 deletions
+5
View File
@@ -3,6 +3,7 @@ import { writeFile } from "node:fs/promises";
import { basename, join } from "node:path";
import { blurFaces } from "@stirling-image/ai";
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { autoOrient } from "../../lib/auto-orient.js";
import { validateImageBuffer } from "../../lib/file-validation.js";
import { createWorkspace } from "../../lib/workspace.js";
import { updateSingleFileProgress } from "../progress.js";
@@ -52,6 +53,10 @@ export function registerBlurFaces(app: FastifyInstance) {
try {
const settings = settingsRaw ? JSON.parse(settingsRaw) : {};
// Auto-orient to fix EXIF rotation before face detection
fileBuffer = await autoOrient(fileBuffer);
const jobId = randomUUID();
const workspacePath = await createWorkspace(jobId);
@@ -69,11 +69,6 @@ export function BlurFacesSettings() {
</div>
</div>
{/* Info */}
<p className="text-[10px] text-muted-foreground">
Uses MediaPipe for face detection. Automatically detects and blurs all faces in the image.
</p>
{/* Error */}
{error && <p className="text-xs text-red-500">{error}</p>}
@@ -91,7 +86,6 @@ export function BlurFacesSettings() {
active={processing}
phase={progress.phase === "idle" ? "uploading" : progress.phase}
label="Blurring faces"
stage={progress.stage}
percent={progress.percent}
elapsed={progress.elapsed}
/>