hacksider / Deep-Live-Cam

real time face swap and one-click video deepfake with only a single image
GNU Affero General Public License v3.0
41.22k stars 6.01k forks source link

BOUNTY: Mouth Mask Feature #740

Closed KRSHH closed 1 month ago

KRSHH commented 1 month ago

Summary by Sourcery

Implement a mouth mask feature in the face swapping module to enhance realism by separately handling the mouth area. Update the UI to include switches for enabling the mouth mask and visualizing the mouth mask box, giving users more control over the feature.

New Features:

Enhancements:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This PR implements a mouth mask feature for face swapping that preserves the original mouth area of the target face. The implementation includes mask creation, color correction, and visualization capabilities. The changes primarily affect the face swapper module and add new UI controls.

Class diagram for the updated face swapper module

classDiagram
    class FaceSwapper {
        +get_face_swapper() : Any
        +swap_face(source_face: Face, target_face: Face, temp_frame: Frame) : Frame
        +process_frame(source_face: Face, temp_frame: Frame) : Frame
        +process_frame_v2(temp_frame: Frame, temp_frame_path: str) : Frame
        +process_frames(source_path: str, temp_frame_paths: List[str], progress: Any) : None
        +process_image(source_path: str, target_path: str, output_path: str) : None
        +process_video(source_path: str, temp_frame_paths: List[str]) : None
        +create_lower_mouth_mask(face: Face, frame: Frame) : (np.ndarray, np.ndarray, tuple, np.ndarray)
        +draw_mouth_mask_visualization(frame: Frame, face: Face, mouth_mask_data: tuple) : Frame
        +apply_mouth_area(frame: np.ndarray, mouth_cutout: np.ndarray, mouth_box: tuple, face_mask: np.ndarray, mouth_polygon: np.ndarray) : np.ndarray
        +create_face_mask(face: Face, frame: Frame) : np.ndarray
        +apply_color_transfer(source, target)
    }

    class UI {
        +create_root(start: Callable[[], None], destroy: Callable[[], None]) : ctk.CTk
    }

    class Globals {
        +mouth_mask: bool
        +show_mouth_mask_box: bool
        +mask_feather_ratio: int
        +mask_down_size: float
        +mask_size: int
    }

    FaceSwapper --> UI : uses
    FaceSwapper --> Globals : uses
    UI --> Globals : uses
    note for FaceSwapper "New methods for mouth mask feature added"
    note for UI "New UI controls for mouth mask feature added"
    note for Globals "New global variables for mouth mask feature added"

File-Level Changes

Change Details Files
Added mouth mask functionality to preserve original mouth area during face swapping
  • Implemented create_lower_mouth_mask function to generate a mask for the lower face area
  • Added color transfer functionality to blend the preserved mouth area naturally
  • Created face mask generation for better blending with the swapped face
  • Integrated mouth mask processing into the main face swapping pipeline
modules/processors/frame/face_swapper.py
Added UI controls for mouth mask features
  • Added toggle switch for enabling/disabling mouth mask
  • Added toggle switch for showing mouth mask visualization
  • Added mouth mask configuration parameters
modules/ui.py
modules/globals.py
Added visualization and debugging features for mouth mask
  • Implemented draw_mouth_mask_visualization function for debugging
  • Added mask feathering for smooth blending
  • Added configurable parameters for mask size and feathering
modules/processors/frame/face_swapper.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
KRSHH commented 1 month ago

Directly commited to main last time (now reverted)... my mistake