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
34.93k stars 4.93k forks source link

Two face feature and multi target face placement control #398

Closed iVideoGameBoss closed 3 weeks ago

iVideoGameBoss commented 3 weeks ago

Two Face Feature and Face Controls

Added a new feature that can work with two faces in source image and replace two target faces on webcam, video or image. You can select a source image that has one or two faces. Left face in source image will replace left target face and right face in source image will replace right target face. You can also control how one face is replaced if two target faces are on webcam, video or image from left or right.

Two faces replaced on webcam

DemoTwoFace

Works with Video and Images

DemoTwoFace

Face placement controls

FaceControls

Show both faces - When you select a source image with two faces you will need to enable this option to replace both target faces on webcam, video or image. By default left face is always used. If your video has one target face or two target faces and one target face goes out of frame than left face is always used on target face.

Flip left/right faces - Turning on this option will flip source faces on target faces to right->left. You can flip both source faces in your webcam, video or image when two target faces are present. By default left face will replace left target face and right face will replace right target face.

Detect face from right - Turning on this option will replace target face detected from right of frame when two target faces are present. By default the target face/s is detected from left of webcam, video or image.

Summary by Sourcery

Add a new feature to support replacing two target faces using a source image with one or two faces. Implement face placement controls to customize face replacement behavior. Update documentation to reflect these changes and guide contributors.

New Features:

Enhancements:

Documentation:

sourcery-ai[bot] commented 3 weeks ago

Reviewer's Guide by Sourcery

This pull request introduces a new feature for handling two faces in source images and replacing two target faces on webcam, video, or image. The implementation includes new UI controls for face placement, modifications to the face swapping process, and updates to the documentation. Key changes involve refactoring the frame processing logic, updating the UI to include new controls, and enhancing the README with information about the new features.

File-Level Changes

Files Changes
modules/ui.py Added new UI controls for two-face feature, including 'Show both faces', 'Flip left/right faces', and 'Detect face from right'
modules/processors/frame/face_swapper.py Refactored face swapping process to support two faces by modifying the frame processing logic
README.md Updated README with information about the new two-face feature, usage instructions, and demo images
modules/face_analyser.py Added new functions to detect left and right faces in an image
modules/core.py Added new command-line arguments for two-face feature controls
modules/globals.py Added new global variables for two-face feature controls
CONTRIBUTING.md Created CONTRIBUTING.md file with guidelines for contributors

Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.
vic4key commented 3 weeks ago

@iVideoGameBoss Thank you for the pull request. Before I do a merging into the branch, could you please update the codes to support multiple faces? This will ensure the feature is more versatile and can handle various scenarios. Thanks!

iVideoGameBoss commented 3 weeks ago

@iVideoGameBoss Thank you for the pull request. Before I do a merging into the branch, could you please update the codes to support multiple faces? This will ensure the feature is more versatile and can handle various scenarios. Thanks!

"Thank you for reviewing my pull request! I appreciate the feedback.

To clarify, the code already supports multiple faces. Here’s how it works:

Multiple Source Faces: The program can handle either one or two source faces. When two source faces are provided, the first detected target face from the left is replaced with the first source face, and the next detected face is replaced with the second source face. If there are more than two faces on the target frame, then the first two detected faces from the left are replaced.

Single Source Face: When only one source face is provided, it’s duplicated internally to ensure the same functionality. The 'show both faces' option will replace the first detected face with the left source face and the next one with the right source face.

Behavior Consistency: The 'many faces' option works as before, replacing all detected faces with the left source face by default. If there are two source faces, you can choose which one to use for the 'many faces' option with the flip feature that I will add.

This approach keeps the functionality consistent with previous versions while adding flexibility for handling multiple faces.

I will add code to support to many face option so you can at least flip which source face to use.

iVideoGameBoss commented 3 weeks ago

@iVideoGameBoss Thank you for the pull request. Before I do a merging into the branch, could you please update the codes to support multiple faces? This will ensure the feature is more versatile and can handle various scenarios. Thanks!

I added two face flip support to many face option. So when you have two faces in source image and one, two or more faces in target, You can flip between the two faces on many face option. As mentioned above, when you have one source face it will also be loaded as second face. So when you flip a face it still remains same face and will work with many face option.

vic4key commented 3 weeks ago

@iVideoGameBoss Sorry for the late reply. This function takes time to review when I'm busy, so I cannot reply quickly.

Your PR seem only support two faces, it seems does not cover to support multiple faces. The design should:

  1. List all person faces in the image/video/frame.
  2. Add a UI to pick the replacement face for each one to create a list of face mappings.
  3. Then, based on this mapping, swap faces during Start/Live.

This will ensure the feature is more versatile and can handle various scenarios, and better for maintaining the codes later.

I appreciate your contribution, but If you do not have time to update your codes. Please wait for support of the multiple faces in the later version. Thanks.

Like this image

hacksider commented 2 weeks ago

@iVideoGameBoss just want to ask if you want to be a collaborator of this repo :) I saw you're doing a lot of stuffs and I want the community to see your visions as well.

iVideoGameBoss commented 2 weeks ago

@iVideoGameBoss just want to ask if you want to be a collaborator of this repo :) I saw you're doing a lot of stuffs and I want the community to see your visions as well.

sure. that would be really cool