fixed visualizer, fixed mask width/height

main
kex0 2023-05-12 01:05:27 +02:00
parent 5930ba5056
commit fd7d2ca826
2 changed files with 18 additions and 9 deletions

View File

@ -205,7 +205,7 @@ def findFaces(facecfg, image, width, height, divider, onlyHorizontal, onlyVertic
# except cv2.error:
# mask = dilated
if singleMaskPerImage:
if singleMaskPerImage and len(binary_masks) > 0:
result = []
h, w = binary_masks[0].shape
result = np.full((h,w), 0, dtype=np.uint8)
@ -587,14 +587,17 @@ class Script(scripts.Script):
# if len(masks)==0 and path != '':
masks, totalNumberOfFaces, faces_info, skip = findFaces(facecfg, image, width, height, divider, onlyHorizontal, onlyVertical, file=None, totalNumberOfFaces=totalNumberOfFaces, singleMaskPerImage=True, countFaces=False, maskWidth=maskWidth, maskHeight=maskHeight, skip=0)
mask = masks[0]
if len(masks) > 0:
mask = masks[0]
else:
mask = np.zeros((image.height, image.width, 3), dtype=np.uint8)
# mask = maskResize(mask, maskSize, height)
mask = Image.fromarray(mask)
redImage = Image.new("RGB", (width, height), (255, 0, 0))
mask.convert("L")
mask = mask.convert("L")
draw = ImageDraw.Draw(mask, "L")
if divider > 1:
@ -622,14 +625,17 @@ class Script(scripts.Script):
# if len(masks)==0 and path != '':
masks, totalNumberOfFaces, faces_info, skip = findFaces(facecfg, image, width, height, divider, onlyHorizontal, onlyVertical, file=None, totalNumberOfFaces=totalNumberOfFaces, singleMaskPerImage=True, countFaces=False, maskWidth=maskWidth, maskHeight=maskHeight, skip=0)
mask = masks[0]
if len(masks) > 0:
mask = masks[0]
else:
mask = np.zeros((image.height, image.width, 3), dtype=np.uint8)
# mask = maskResize(mask, maskSize, height)
mask = Image.fromarray(mask)
redImage = Image.new("RGB", (width, height), (255, 0, 0))
mask.convert("L")
mask = mask.convert("L")
draw = ImageDraw.Draw(mask, "L")
if divider > 1:
@ -650,14 +656,17 @@ class Script(scripts.Script):
# if len(masks)==0 and path != '':
masks, totalNumberOfFaces, faces_info, skip = findFaces(facecfg, image, width, height, divider, onlyHorizontal, onlyVertical, file=None, totalNumberOfFaces=totalNumberOfFaces, singleMaskPerImage=True, countFaces=False, maskWidth=maskWidth, maskHeight=maskHeight, skip=0)
mask = masks[0]
if len(masks) > 0:
mask = masks[0]
else:
mask = np.zeros((image.height, image.width, 3), dtype=np.uint8)
# mask = maskResize(mask, maskSize, height)
mask = Image.fromarray(mask)
redImage = Image.new("RGB", (width, height), (255, 0, 0))
mask.convert("L")
mask = mask.convert("L")
draw = ImageDraw.Draw(mask, "L")
if divider > 1:

View File

@ -59,8 +59,8 @@ def maskResize(mask, maskWidth, maskHeight):
# Resize the cropped image by percentage
height, width = cropped.shape[:2]
new_height = max(int(height * maskWidth / 100), 1)
new_width = max(int(width * maskHeight / 100), 1)
new_height = max(int(height * maskHeight / 100), 1)
new_width = max(int(width * maskWidth / 100), 1)
resized = cv2.resize(cropped, (new_width, new_height))
# Create black image with same resolution as original image