forked from deepfakes/faceswap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging' of https://github.com/deepfakes/faceswap into …
…staging
- Loading branch information
Showing
5 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python3 | ||
""" Manual Balance colour adjustment plugin for faceswap.py converter """ | ||
|
||
import cv2 | ||
import numpy as np | ||
from ._base import Adjustment | ||
|
||
|
||
class Color(Adjustment): | ||
""" Adjust the mean of the color channels to be the same for the swap and old frame """ | ||
|
||
def process(self, old_face, new_face, raw_mask): | ||
image = self.convert_colorspace(new_face * 255.0) | ||
adjustment = np.array([self.config["balance_1"] / 100.0, | ||
self.config["balance_2"] / 100.0, | ||
self.config["balance_3"] / 100.0]).astype("float32") | ||
for idx in range(3): | ||
if adjustment[idx] >= 0: | ||
image[:, :, idx] = ((1 - image[:, :, idx]) * adjustment[idx]) + image[:, :, idx] | ||
else: | ||
image[:, :, idx] = image[:, :, idx] * (1 + adjustment[idx]) | ||
|
||
image = self.convert_colorspace(image * 255.0, to_bgr=True) | ||
return image | ||
|
||
def convert_colorspace(self, new_face, to_bgr=False): | ||
""" Convert colorspace based on mode or back to bgr """ | ||
mode = self.config["colorspace"].lower() | ||
colorspace = "YCrCb" if mode == "ycrcb" else mode.upper() | ||
conversion = "{}2BGR".format(colorspace) if to_bgr else "BGR2{}".format(colorspace) | ||
image = cv2.cvtColor(new_face.astype("uint8"), # pylint: disable=no-member | ||
getattr(cv2, "COLOR_{}".format(conversion))).astype("float32") / 255.0 | ||
return image |
This file contains 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