change face info from dict to obj

dev
Robert Barron 2023-03-12 21:13:24 -07:00
parent 4d5efefcb8
commit 63401c95c2
2 changed files with 11 additions and 6 deletions

View File

@ -226,7 +226,7 @@ def faceSwap(p, masks, image, finishedImages, invertMask, forced_filename, pathT
for i in range(len(faces_info)):
try:
pixel_color = mask.getpixel((faces_info[i]["center"][0],faces_info[i]["center"][1]))
pixel_color = mask.getpixel((faces_info[i].center[0],faces_info[i].center[1]))
except IndexError:
pixel_color = 0
if pixel_color == 255:
@ -241,10 +241,10 @@ def faceSwap(p, masks, image, finishedImages, invertMask, forced_filename, pathT
image_cropped = image
rotation_threshold = rotation_threshold
if 90+rotation_threshold > faces_info[index]["angle"] and 90-rotation_threshold < faces_info[index]["angle"]:
if 90+rotation_threshold > faces_info[index].angle and 90-rotation_threshold < faces_info[index].angle:
pass
else:
angle_difference = (90-int(faces_info[index]["angle"]) + 360) % 360
angle_difference = (90-int(faces_info[index].angle) + 360) % 360
image = image.rotate(angle_difference, expand=True)
image_mask = image_mask.rotate(angle_difference, expand=True)
rotate = True
@ -265,7 +265,7 @@ def faceSwap(p, masks, image, finishedImages, invertMask, forced_filename, pathT
if rotate:
for i in range(len(proc.images)):
image_copy = image_cropped.copy()
proc.images[i] = proc.images[i].rotate(int(faces_info[index]["angle"])-90)
proc.images[i] = proc.images[i].rotate(int(faces_info[index].angle)-90)
w1, h1 = image_cropped.size
w2, h2 = proc.images[i].size
x = (w1 - w2) // 2

View File

@ -110,6 +110,11 @@ def getFacialLandmarks(image, facecfg):
return facelandmarks
class FaceInfo():
def __init__(self, center, rotation):
self.center = center
self.angle = rotation
def computeFaceInfo(landmark, onlyHorizontal, divider, small_width, small_height, small_image_index):
x_chin = landmark[152][0]
y_chin = -landmark[152][1]
@ -129,7 +134,7 @@ def computeFaceInfo(landmark, onlyHorizontal, divider, small_width, small_height
x = ((small_image_index % divider) * small_width ) + landmark[0][0]
y = ((small_image_index // divider) * small_height) + landmark[0][1]
return { "angle": face_angle, "center": (x,y) }
return FaceInfo((x,y), face_angle)
# try to get landmarks for a face located at rect
def getFacialLandmarkConvexHull(image, rect, onlyHorizontal, divider, small_width, small_height, small_image_index, facecfg):
@ -221,7 +226,7 @@ def getFacialLandmarkConvexHull(image, rect, onlyHorizontal, divider, small_widt
# compute face_info and translate it back into the coordinate space
face_info = computeFaceInfo(best_landmark, onlyHorizontal, divider, small_width, small_height, small_image_index)
face_info["center"] = (face_info["center"][0] + subrect_x0, face_info["center"][1] + subrect_y0)
face_info.center = (face_info.center[0] + subrect_x0, face_info.center[1] + subrect_y0)
return best_hull, face_info