Deep-Live-Cam
Deep-Live-Cam copied to clipboard
Implement advanced color correction and Poisson blending.
- Added histogram-based color correction to
face_swapper.pyfor improved color matching of the swapped face to the target frame. Controlled by--color-correction. - Integrated Poisson blending (
cv2.seamlessClone) for smoother face integration, reducing visible seams. Controlled by--poisson-blending. - Added global variables
use_poisson_blendingandpoisson_blending_feather_amountand corresponding command-line arguments. - Refined argument parsing in
core.pyfor new features. - Updated
swap_facelogic to incorporate these features and handle potential errors during blending.
Summary by Sourcery
Implement advanced color correction and Poisson blending options in the face swapper, including command-line controls, validation/fallback handling, and related helper logic
New Features:
- Add optional histogram-based color correction to match the swapped face’s color distribution to the target frame
- Add optional Poisson blending integration for seamless face insertion and reduced seams
Enhancements:
- Improve swap_face workflow with validation and fallbacks for failed swaps and blending errors
- Expose new flags (--color-correction, --poisson-blending) and globals with refined argument parsing and default settings
Reviewer's Guide
This PR enhances the face swapping pipeline by introducing optional histogram-based color correction and Poisson blending, updating the swap_face logic to apply region-aware adjustments, generate and feather blending masks, handle errors robustly, and expose these features via new CLI flags and globals.
Sequence diagram for face swapping with color correction and Poisson blending
sequenceDiagram
participant User as actor User
participant CLI as CLI Parser
participant Core as core.py
participant Globals as modules.globals
participant Swapper as swap_face()
participant Frame as Frame
User->>CLI: Run with --color-correction and/or --poisson-blending
CLI->>Core: parse_args()
Core->>Globals: Set color_correction, use_poisson_blending
Core->>Swapper: swap_face(source_face, target_face, temp_frame)
Swapper->>Swapper: Apply face swap
alt Color correction enabled
Swapper->>Swapper: Apply histogram-based color correction
end
alt Poisson blending enabled
Swapper->>Swapper: Generate/feather mask
Swapper->>Swapper: Apply cv2.seamlessClone
end
Swapper->>Frame: Return blended frame
Frame-->>Core: Frame with improved integration
Class diagram for updated swap_face logic and new color correction function
classDiagram
class swap_face {
+Frame swap_face(Face source_face, Face target_face, Frame temp_frame)
+Handles: color correction, Poisson blending, error handling
}
class apply_histogram_matching_color_correction {
+Frame apply_histogram_matching_color_correction(Frame source_img, Frame target_img)
+Performs histogram matching on B, G, R channels
}
swap_face ..> apply_histogram_matching_color_correction : uses
class modules.globals {
+bool color_correction
+bool use_poisson_blending
+int poisson_blending_feather_amount
}
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Validate face swap output and rename intermediate variable |
|
modules/processors/frame/face_swapper.py |
| Implement histogram-based color correction |
|
modules/processors/frame/face_swapper.py |
| Integrate Poisson blending with mask generation |
|
modules/processors/frame/face_swapper.py |
| Refine process_frame color conversion logic |
|
modules/processors/frame/face_swapper.py |
| Add histogram matching helper function |
|
modules/processors/frame/face_swapper.py |
| Extend CLI and global flags for new features |
|
modules/core.pymodules/globals.py |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon 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. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard 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 for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.