Deep-Live-Cam/modules
google-labs-jules[bot] 37486f03e7 feat: Implement hair swapping and enhance realism
This commit introduces the capability to swap hair along with the face from a source image to a target image/video or live webcam feed.

Key changes include:

1.  **Hair Segmentation:**
    - Integrated the `isjackwild/segformer-b0-finetuned-segments-skin-hair-clothing` model from Hugging Face using the `transformers` library.
    - Added `modules/hair_segmenter.py` with a `segment_hair` function to produce a binary hair mask from an image.
    - Updated `requirements.txt` with `transformers`.

2.  **Combined Face-Hair Mask:**
    - Implemented `create_face_and_hair_mask` in `modules/processors/frame/face_swapper.py` to generate a unified mask for both face (from landmarks) and segmented hair from the source image.

3.  **Enhanced Swapping Logic:**
    - Modified `swap_face` and related processing functions (`process_frame`, `process_frame_v2`, `process_frames`, `process_image`) to utilize the full source image (`source_frame_full`).
    - The `swap_face` function now performs the standard face swap and then:
        - Segments hair from the `source_frame_full`.
        - Warps the hair and its mask to the target face's position using an affine transformation estimated from facial landmarks.
        - Applies color correction (`apply_color_transfer`) to the warped hair.
        - Blends the hair onto the target frame, preferably using `cv2.seamlessClone` for improved realism.
    - Existing mouth mask logic is preserved and applied to the final composited frame.

4.  **Webcam Integration:**
    - Updated the webcam processing loop in `modules/ui.py` (`create_webcam_preview`) to correctly load and pass the `source_frame_full` to the frame processors.
    - This enables hair swapping in live webcam mode.
    - Added error handling for source image loading in webcam mode.

This set of changes addresses your request for more realistic face swaps that include hair. Further testing and refinement of blending parameters may be beneficial for optimal results across all scenarios.
2025-05-21 18:47:31 +00:00
..
processors feat: Implement hair swapping and enhance realism 2025-05-21 18:47:31 +00:00
__init__.py Update __init__.py 2025-05-13 00:14:49 +08:00
capturer.py Revert "recommit webcam option" 2024-09-11 02:49:53 +08:00
cluster_analysis.py Added ability to map faces 2024-09-10 05:40:55 +05:30
core.py add mutil language 2025-01-07 14:04:18 +08:00
face_analyser.py fix: typo souce_target_map → source_target_map 2025-02-03 20:33:44 +09:00
gettext.py add mutil language 2025-01-07 14:04:18 +08:00
globals.py fix: typo souce_target_map → source_target_map 2025-02-03 20:33:44 +09:00
hair_segmenter.py feat: Implement hair swapping and enhance realism 2025-05-21 18:47:31 +00:00
metadata.py Revert "Update metadata.py" 2025-04-17 02:39:05 +08:00
predicter.py add toggle button for blueish cam fix (Force OpenCV2 BGR2RGB) 2024-08-30 22:02:23 +02:00
typing.py initial commit 2023-09-24 21:36:57 +08:00
ui.json reverted to the old version 2024-09-19 17:38:02 +08:00
ui.py feat: Implement hair swapping and enhance realism 2025-05-21 18:47:31 +00:00
utilities.py Adding Pygrabber as Cam manager 2024-12-13 19:49:11 +05:30
video_capture.py Pygrabber only for Windows 2024-12-16 18:41:39 +05:30