mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-29 19:20:03 -07:00
fix error on small mask region size in converter,
error catching on convert face
This commit is contained in:
parent
b52793218e
commit
1bd3a8e0c1
2 changed files with 127 additions and 114 deletions
|
@ -171,12 +171,19 @@ class ConvertSubprocessor(SubprocessorBase):
|
|||
faces_processed = 1
|
||||
elif self.converter.get_mode() == ConverterBase.MODE_FACE:
|
||||
faces = self.alignments[filename_path.stem]
|
||||
for image_landmarks in faces:
|
||||
for face_num, image_landmarks in enumerate(faces):
|
||||
try:
|
||||
if self.debug:
|
||||
print ( '\nConverting face_num [%d] in file [%s]' % (face_num, filename_path) )
|
||||
|
||||
image = self.converter.convert_face(image, image_landmarks, self.debug)
|
||||
if self.debug:
|
||||
for img in image:
|
||||
cv2.imshow ('Debug convert', img )
|
||||
cv2.waitKey(0)
|
||||
except Exception as e:
|
||||
print ( 'Error while converting face_num [%d] in file [%s]: %s' % (face_num, filename_path, str(e)) )
|
||||
traceback.print_exc()
|
||||
faces_processed = len(faces)
|
||||
|
||||
if not self.debug:
|
||||
|
|
|
@ -104,8 +104,13 @@ class ConverterMasked(ConverterBase):
|
|||
if maxregion.size != 0:
|
||||
miny,minx = maxregion.min(axis=0)[:2]
|
||||
maxy,maxx = maxregion.max(axis=0)[:2]
|
||||
|
||||
if debug:
|
||||
print ("maxregion.size: %d, minx:%d, maxx:%d miny:%d, maxy:%d" % (maxregion.size, minx, maxx, miny, maxy ) )
|
||||
|
||||
lenx = maxx - minx
|
||||
leny = maxy - miny
|
||||
if lenx >= 4 and leny >= 4:
|
||||
masky = int(minx+(lenx//2))
|
||||
maskx = int(miny+(leny//2))
|
||||
lowest_len = min (lenx, leny)
|
||||
|
@ -117,7 +122,7 @@ class ConverterMasked(ConverterBase):
|
|||
blur = int( lowest_len * 0.10 * 0.01*self.blur_mask_modifier )
|
||||
|
||||
if debug:
|
||||
print ("ero = %d, blur = %d" % (ero, blur) )
|
||||
print ("erode_size = %d, blur_size = %d" % (ero, blur) )
|
||||
|
||||
img_mask_blurry_aaa = img_face_mask_aaa
|
||||
if self.erode_mask:
|
||||
|
@ -179,6 +184,7 @@ class ConverterMasked(ConverterBase):
|
|||
out_img = np.clip( img_bgr*(1-img_face_mask_aaa) + (out_img*img_face_mask_aaa) , 0, 1.0 )
|
||||
if debug:
|
||||
debugs += [out_img.copy()]
|
||||
|
||||
out_img = cv2.seamlessClone( (out_img*255).astype(np.uint8), (img_bgr*255).astype(np.uint8), (img_face_mask_flatten_aaa*255).astype(np.uint8), (masky,maskx) , cv2.NORMAL_CLONE )
|
||||
out_img = out_img.astype(np.float32) / 255.0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue