-
Notifications
You must be signed in to change notification settings - Fork 148
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
How to eliminate the white edge of mask? #12
Comments
If you want to eliminate it, you can apply this patch diff --git a/utils/aux_functions.py b/utils/aux_functions.py
index df556ba..40c7484 100644
--- a/utils/aux_functions.py
+++ b/utils/aux_functions.py
@@ -282,7 +282,7 @@ def get_angle(line1, line2):
def mask_face(image, face_location, six_points, angle, args, type="surgical"):
# Find the face angle
threshold = 13
@@ -356,9 +356,22 @@ def mask_face(image, face_location, six_points, angle, args, type="surgical"):
# Apply mask
mask_inv = cv2.bitwise_not(mask)
- img_bg = cv2.bitwise_and(image, image, mask=mask_inv)
- img_fg = cv2.bitwise_and(dst_mask, dst_mask, mask=mask)
- out_img = cv2.add(img_bg, img_fg[:, :, 0:3])
+ # img_bg = cv2.bitwise_and(image, image, mask=mask_inv)
+ # img_fg = cv2.bitwise_and(dst_mask, dst_mask, mask=mask)
+
+ img_bg = image.astype(np.float32)
+ _t = mask_inv.astype(np.float32) / 255
+ img_bg[:,:,0] *= _t
+ img_bg[:, :, 1] *= _t
+ img_bg[:, :, 2] *= _t
+
+ img_fg = dst_mask.astype(np.float32)
+ _t = mask.astype(np.float32) / 255
+ img_fg[:, :, 0] *= _t
+ img_fg[:, :, 1] *= _t
+ img_fg[:, :, 2] *= _t
+
+ out_img = cv2.add(img_bg.astype(np.uint8), img_fg[:, :, 0:3].astype(np.uint8))
if "empty" in type or "inpaint" in type:
out_img = img_bg
# Plot key points |
It seems to work well. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I found there are some white edges of masks on faces. And how to eliminate this unexpected phenomenon? Thanks~
The text was updated successfully, but these errors were encountered: