Nodes/face_mosaic/选择性人脸马赛克(指定人物)
ComfyUI Node

选择性人脸马赛克(指定人物)

Mosaic only the person you name — face recognition in one node

By yzzky·Created 12 months ago·Updated 12 months ago· 0
选择性人脸马赛克(指定人物)
    • output_video_path
    • processing_info
    ◄video_path►
    ◄reference_images►
    ◄recognition_backend▾►
    ◄similarity_threshold0.60►
    ◄mosaic_size20►
    ◄mosaic_type▾►
    ◄output_format▾►
    ◄use_gputrue►
    ◄output_path►
    ◄use_ffmpeg_encodetrue►
    ◄ffmpeg_crf23►
    ◄ffmpeg_preset▾►
    ◄copy_audiotrue►

    Every other node in this pack mosaics everyone. That's the wrong answer half the time - you want to obscure the bystander while leaving the speaker visible, or mask the guest but not the host. This node is the pack's smart one: you give it reference photos of the person (or people) to hide, and it only mosaics faces that match, leaving everyone else untouched. It's the "选择性人脸马赛克(指定人物)" entry - selective face mosaic (specified person) - under YZZ_Face_Mosaic/Selective.

    How it works

    This is real face recognition, not just detection. On init the node builds a recognizer using one of two backends:

    • insightface - FaceAnalysis with buffalo_l, the same RetinaFace detection plus the recognition embeddings the face-swap community uses. Heavier, generally better.
    • facenet - MTCNN for detection plus InceptionResnetV1 pretrained on VGGFace2 for the embeddings. Lighter, respectable.

    For each reference image (one file path per line in the reference_images box) it extracts an embedding. Then for every frame it detects faces, embeds each one, and computes cosine similarity against your references. If the score clears similarity_threshold, that face gets mosaicked; if not, it passes through. similarity_threshold runs 0.3–0.9, default 0.6 - lower is more aggressive (mosaics lookalikes and false positives), higher is stricter (can start missing your actual target when lighting shifts).

    The inputs that matter

    • reference_images - multiline, one path per line. Clear photos of the person's face work best; a couple of angles beat one straight-on shot.
    • recognition_backend - insightface for accuracy, facenet for lighter installs.
    • similarity_threshold - the only knob that determines who's "the target." Start at 0.6 and adjust up if strangers get masked, down if your person keeps escaping.
    • mosaic_size, mosaic_type, output_format, use_gpu - the pack's usual suspects.

    Outputs are output_video_path and processing_info. If you leave use_ffmpeg_encode on (default), the video gets re-encoded with ffmpeg - CRF quality via ffmpeg_crf and ffmpeg_preset, audio copied unless you flip copy_audio off. This needs ffmpeg on your PATH; without it, the node logs a notice and keeps the plain OpenCV output.

    Installing it - two installs, not one

    Beyond the pack itself (ComfyUI Manager → yzz_face_mosaic, or git clone https://github.com/yzzky/yzz_face_mosaic + pip install -r requirements.txt), you must install the recognition backend - it is not in requirements.txt:

    pip install insightface onnxruntime-gpu    # for the insightface backend
    # or
    pip install facenet-pytorch                # for the facenet backend
    

    InsightFace's first run downloads the buffalo_l weights; facenet's VGGFace2 weights also download on first use. Restart ComfyUI after installing.

    Where it bites

    Embeddings are sensitive to faces looking very different from your reference (new glasses, dramatic hair, harsh lighting), so keep the threshold modest and include variety in references. And remember: if the recognizer itself isn't installed, the node returns no matches and your video ships with nobody masked - check the console. It's the most useful node in the pack for real-world "hide this one person" work, but it's also the one with the most moving parts.

    CategoryYZZ_Face_Mosaic/Selective

    Inputs (13)

    NameTypeDefaultDescription
    video_pathSTRING—
    reference_imagesSTRING—
    recognition_backendCOMBO2 options: insightface, facenet
    similarity_thresholdFLOAT0.600.3–0.9—
    mosaic_sizeINT205–100—
    mosaic_typeCOMBO3 options: pixelate, blur, black_box
    output_formatCOMBO3 options: mp4, avi, mov
    use_gpuBOOLEANtrue—
    output_pathoptSTRING—
    use_ffmpeg_encodeoptBOOLEANtrue—
    ffmpeg_crfoptINT2316–32—
    ffmpeg_presetoptCOMBO9 options: ultrafast, superfast, veryfast, faster, fast, medium, +3
    copy_audiooptBOOLEANtrue—

    Outputs (2)

    NameTypeDescription
    output_video_pathSTRING—
    processing_infoSTRING—