-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Implement advanced color correction and Poisson blending. #1380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
netmirror-apple9
wants to merge
6
commits into
hacksider:main
Choose a base branch
from
netmirror-apple9:Live-Cam-Colour
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Added histogram-based color correction to `face_swapper.py` for 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_blending` and `poisson_blending_feather_amount` and corresponding command-line arguments. - Refined argument parsing in `core.py` for new features. - Updated `swap_face` logic to incorporate these features and handle potential errors during blending.
Reviewer's GuideThis 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 blendingsequenceDiagram
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 functionclassDiagram
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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
- Updated `face_swapper.py` to prioritize using the face bounding box (bbox) for creating the Poisson blending mask. This provides a tighter mask around the swapped face area, aiming to reduce artifacts near ears/hairline. - Implemented fallback to landmark-based convex hull if bbox is invalid or unavailable. - Added logging for mask generation issues and skipping blending if no valid mask can be created.
- Added functionality to preserve target's ears when using Poisson blending. - Introduced new global variables in `globals.py`: - `preserve_target_ears` (boolean flag) - `ear_width_ratio` - `ear_height_ratio` - `ear_vertical_offset_ratio` - `ear_horizontal_overlap_ratio` - Added command-line argument `--preserve-ears` to `core.py`. - Modified `face_swapper.py` to adjust the Poisson blending mask by subtracting calculated ear regions if `preserve_target_ears` is true. This aims to reduce artifacts around ears by using the original target frame's ear content.
This commit includes: - Refactored modules/ui.py: Live webcam preview loop now uses ROOT.after() for better UI responsiveness and potentially smoother external capture. - Refactored modules/video_capture.py: Implemented threaded, non-blocking frame reads for improved camera capture performance and stability. - Feature: Ear preservation for Poisson blending to reduce artifacts (controlled by --preserve-ears and related globals). - Feature: Histogram-based color correction (--color-correction). - Feature: Poisson blending for smoother face integration (--poisson-blending). These changes aim to improve overall swap quality, UI stability, and address reported FPS issues with external capture tools like SplitCam.
…invalid. - Modified `create_webcam_preview` in `modules/ui.py` to handle errors during source image loading (e.g., file not readable, no face detected) more gracefully. - Instead of stopping the live preview, it now shows a warning message and starts the live camera feed without face swapping if the source image is unusable. - This addresses the issue where clicking 'Live' after selecting a problematic source image would cause the preview to stop or crash immediately.
- Modified `update_webcam_frame_after` in `modules/ui.py` to use the source_image passed from `create_webcam_preview` without attempting to reload it on every frame if it was initially None. - This fixes an FPS drop regression that occurred when starting the live preview with a problematic or non-existent source image.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
face_swapper.py
for improved color matching of the swapped face to the target frame. Controlled by--color-correction
.cv2.seamlessClone
) for smoother face integration, reducing visible seams. Controlled by--poisson-blending
.use_poisson_blending
andpoisson_blending_feather_amount
and corresponding command-line arguments.core.py
for new features.swap_face
logic 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:
Enhancements: