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 Masking #738

Closed GhoulBoii closed 1 month ago

GhoulBoii commented 1 month ago

The menu is a bit messed up at the moment. I will try fixing it in the morning. UI has been made uniform with the switches being added with the others. I did limited testing on my workstation and it worked. However, the live preview was coming frame-by-frame so couldn't test in a real world environment.

Summary by Sourcery

Implement mouth masking feature to enhance face swapping by preserving the original mouth area. Update the UI to include controls for toggling mouth mask options.

New Features:

Enhancements:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This PR implements mouth masking functionality during face swapping, allowing the original mouth area to be preserved. The implementation includes mask creation, blending algorithms, and UI controls to toggle the feature. The changes primarily affect the face swapping processor and UI components.

User journey diagram for toggling mouth masking feature

journey
    title User Journey for Toggling Mouth Masking Feature
    section UI Interaction
      User -> UI: Open application
      User -> UI: Navigate to settings
      User -> UI: Toggle 'Mouth Mask' switch
    section System Processing
      UI -> System: Update mouth_mask variable
      System -> UI: Reflect change in UI switches
    section Result
      UI -> User: Mouth masking feature toggled
      System -> User: Mouth area preserved during face swap if enabled

Class diagram for face swapping with mouth masking

classDiagram
    class FaceSwapper {
        +pre_check() bool
        +pre_start() bool
        +get_face_swapper() Any
        +create_face_masks(face: Face, frame: Frame) Tuple
        +apply_mouth_area(frame: Frame, mouth_cutout: np.ndarray, mouth_box: Tuple, face_mask: np.ndarray, lower_lip_polygon: Optional[np.ndarray]) Frame
        +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
    }
    note for FaceSwapper "New methods for mouth masking: create_face_masks, apply_mouth_area"

File-Level Changes

Change Details Files
Implement mouth masking functionality in face swapper
  • Add functions to create face and mouth masks using facial landmarks
  • Implement blending algorithm with Gaussian blur for smooth transitions
  • Integrate mouth masking into the main face swapping process
  • Add BLUR_AMOUNT constant for mask edge smoothing
modules/processors/frame/face_swapper.py
Add UI controls for mouth masking feature
  • Add mouth mask toggle switch in main window
  • Add mouth mask toggle switch in preview window
  • Implement synchronization between UI switches
  • Add show mouth mask box option
modules/ui.py
Add global state management for mouth masking
  • Add mouth mask related global variables
  • Add UI component references for state management
modules/globals.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).
GhoulBoii commented 1 month ago

@sourcery-ai review

GhoulBoii commented 1 month ago

@sourcery-ai review

hacksider commented 1 month ago

Hello @GhoulBoii , will review this tomorrow as theres a typhoon in our area. 🥲 Thanks for this push! Will send the bounty as soon as I have checked this.

GhoulBoii commented 1 month ago

Hello @GhoulBoii , will review this tomorrow as theres a typhoon in our area. 🥲 Thanks for this push! Will send the bounty as soon as I have checked this.

No problem! Stay safe and thanks for the bounty.

hacksider commented 1 month ago

Hi there @GhoulBoii , as per testing mouth mask is not working properly. image 😢

hacksider commented 1 month ago

Will be closing this until a new working pull request is submitted.