diff --git a/scripts/batch_face_swap.py b/scripts/batch_face_swap.py index e17ab7c..b7b6bc2 100644 --- a/scripts/batch_face_swap.py +++ b/scripts/batch_face_swap.py @@ -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 diff --git a/scripts/face_detect.py b/scripts/face_detect.py index e49e5f6..ef7d041 100644 --- a/scripts/face_detect.py +++ b/scripts/face_detect.py @@ -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