SMOOTHER MOUTH MASK: Enhanced Blending & Feathering

MOUTH MASK IMPROVEMENTS:
- Increased Gaussian blur from (15,15) to (25,25) for smoother edges
- Enhanced feather amount from 30 to 35 pixels
- Added 1.2x feather multiplier for extra softness
- Additional smoothing pass with (7,7) Gaussian blur

 SMOOTHER RESULTS:
- Much softer mouth mask edges
- Better blending with original mouth
- More natural mouth area transitions
- Reduced harsh edges and artifacts

 TECHNICAL IMPROVEMENTS:
- create_lower_mouth_mask(): Better blur parameters
- apply_mouth_area(): Enhanced feathering algorithm
- Double-pass smoothing for extra softness
- Maintained good FPS performance

 EXPECTED RESULTS:
- Smoother mouth mask appearance
- More natural mouth blending
- Less noticeable mask boundaries
- Professional-looking mouth area preservation
pull/1411/head
asateesh99 2025-07-16 04:42:21 +05:30
parent f08c81f22a
commit 5708be40eb
1 changed files with 8 additions and 3 deletions

View File

@ -470,7 +470,8 @@ def create_lower_mouth_mask(
mask_roi = np.zeros((max_y - min_y, max_x - min_x), dtype=np.uint8) mask_roi = np.zeros((max_y - min_y, max_x - min_x), dtype=np.uint8)
cv2.fillPoly(mask_roi, [expanded_landmarks - [min_x, min_y]], 255) cv2.fillPoly(mask_roi, [expanded_landmarks - [min_x, min_y]], 255)
mask_roi = cv2.GaussianBlur(mask_roi, (15, 15), 5) # Improved smoothing for mouth mask
mask_roi = cv2.GaussianBlur(mask_roi, (25, 25), 8)
mask[min_y:max_y, min_x:max_x] = mask_roi mask[min_y:max_y, min_x:max_x] = mask_roi
mouth_cutout = frame[min_y:max_y, min_x:max_x].copy() mouth_cutout = frame[min_y:max_y, min_x:max_x].copy()
lower_lip_polygon = expanded_landmarks lower_lip_polygon = expanded_landmarks
@ -512,10 +513,14 @@ def apply_mouth_area(frame: np.ndarray, mouth_cutout: np.ndarray, mouth_box: tup
adjusted_polygon = mouth_polygon - [min_x, min_y] adjusted_polygon = mouth_polygon - [min_x, min_y]
cv2.fillPoly(polygon_mask, [adjusted_polygon], 255) cv2.fillPoly(polygon_mask, [adjusted_polygon], 255)
feather_amount = min(30, box_width // modules.globals.mask_feather_ratio, box_height // modules.globals.mask_feather_ratio) # Improved feathering for smoother mouth mask
feathered_mask = cv2.GaussianBlur(polygon_mask.astype(float), (0, 0), feather_amount) feather_amount = min(35, box_width // modules.globals.mask_feather_ratio, box_height // modules.globals.mask_feather_ratio)
feathered_mask = cv2.GaussianBlur(polygon_mask.astype(float), (0, 0), feather_amount * 1.2)
feathered_mask = feathered_mask / feathered_mask.max() feathered_mask = feathered_mask / feathered_mask.max()
# Additional smoothing pass for extra softness
feathered_mask = cv2.GaussianBlur(feathered_mask, (7, 7), 2)
face_mask_roi = face_mask[min_y:max_y, min_x:max_x] face_mask_roi = face_mask[min_y:max_y, min_x:max_x]
combined_mask = feathered_mask * (face_mask_roi / 255.0) combined_mask = feathered_mask * (face_mask_roi / 255.0)
combined_mask = combined_mask[:, :, np.newaxis] combined_mask = combined_mask[:, :, np.newaxis]