mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-12 08:07:03 -07:00
add eye masking code
This commit is contained in:
parent
4850ef4965
commit
60cc917350
2 changed files with 49 additions and 22 deletions
|
@ -372,6 +372,30 @@ def get_image_hull_mask (image_shape, image_landmarks, eyebrows_expand_mod=1.0,
|
|||
ie_polys.overlay_mask(hull_mask)
|
||||
|
||||
return hull_mask
|
||||
|
||||
def get_image_eye_mask (image_shape, image_landmarks):
|
||||
if len(image_landmarks) != 68:
|
||||
raise Exception('get_image_eye_mask works only with 68 landmarks')
|
||||
|
||||
h,w,c = image_shape
|
||||
|
||||
hull_mask = np.zeros( (h,w,1),dtype=np.float32)
|
||||
|
||||
image_landmarks = image_landmarks.astype(np.int)
|
||||
|
||||
cv2.fillConvexPoly( hull_mask, cv2.convexHull( image_landmarks[36:42]), (1,) )
|
||||
cv2.fillConvexPoly( hull_mask, cv2.convexHull( image_landmarks[42:48]), (1,) )
|
||||
|
||||
dilate = h // 32
|
||||
hull_mask = cv2.dilate(hull_mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(dilate,dilate)), iterations = 1 )
|
||||
|
||||
blur = h // 16
|
||||
blur = blur + (1-blur % 2)
|
||||
hull_mask = cv2.GaussianBlur(hull_mask, (blur, blur) , 0)
|
||||
hull_mask = hull_mask[...,None]
|
||||
|
||||
return hull_mask
|
||||
|
||||
|
||||
def alpha_to_color (img_alpha, color):
|
||||
if len(img_alpha.shape) == 2:
|
||||
|
@ -535,17 +559,6 @@ def get_cmask (image_shape, lmrks, eyebrows_expand_mod=1.0):
|
|||
#result = np.clip (result, 0, 1)
|
||||
return result
|
||||
|
||||
def get_image_eye_mask (image_shape, image_landmarks):
|
||||
if len(image_landmarks) != 68:
|
||||
raise Exception('get_image_eye_mask works only with 68 landmarks')
|
||||
|
||||
hull_mask = np.zeros(image_shape[0:2]+(1,),dtype=np.float32)
|
||||
|
||||
cv2.fillConvexPoly( hull_mask, cv2.convexHull( image_landmarks[36:42]), (1,) )
|
||||
cv2.fillConvexPoly( hull_mask, cv2.convexHull( image_landmarks[42:48]), (1,) )
|
||||
|
||||
return hull_mask
|
||||
|
||||
def blur_image_hull_mask (hull_mask):
|
||||
|
||||
maxregion = np.argwhere(hull_mask==1.0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue