""" create_chin_image.py open_mouth.pyの一部 口のオープンに合わせて、あご画像を縦に拡大しているだけ、 輪郭はもう少し綺麗に取りたい https://github.com/akjava/lip_recognition_tools/issues/7 著者: Akihito Miyazaki 作成日: 2024-04-23 更新履歴: - 2024-04-23: 最初のリリース """ import cv2 import numpy as np from PIL import Image import lip_utils def process_chin_image(img,landmarks_list, margin, open_size_y, open_size_x): img_h, img_w = lip_utils.get_image_size(img) open_size_x = 0 #stop support this if open_size_x > 0: print("currently stop support open-sizex") jaw_points = lip_utils.get_jaw_points(landmarks_list) print("### JAW POINT") print(jaw_points) box = lip_utils.points_to_box(jaw_points) print(box) cropped = lip_utils.crop_image_by_box(img,box) cropped_img_h, cropped_img_w = lip_utils.get_image_size(cropped) if lip_utils.DEBUG_CHIN: cv2.imwrite("chin_cropped.jpg",cropped) cropped_jaw_points = lip_utils.offset_points(jaw_points,box[0]) #what hell is this? #points = np.array(jaw_points,dtype=np.float32) # 回転矩形を取得 #rect = cv2.minAreaRect(points) #print(rect) mask = lip_utils.create_mask_from_points(cropped,cropped_jaw_points,4,2) if lip_utils.DEBUG_CHIN: cv2.imwrite("chin_mask.jpg",mask) #lip_utils.print_numpy(mask) chin_image = lip_utils.apply_mask(cropped,mask) chin_image_resized = cv2.resize(chin_image, (cropped_img_w, cropped_img_h+open_size_y), interpolation=cv2.INTER_LANCZOS4) #chin_mask_image_resized = cv2.resize(mask, (cropped_img_w, cropped_img_h+open_size_y), interpolation=cv2.INTER_LANCZOS4) #lip_utils.print_numpy(chin_image) if lip_utils.DEBUG_CHIN: cv2.imwrite("chin_resized.png",chin_image_resized) #alpha image must be save png full_rgba=lip_utils.create_rgba(img_w,img_h) lip_utils.copy_image(full_rgba,chin_image_resized,box[0][0],box[0][1]) if lip_utils.DEBUG_CHIN: cv2.imwrite("chin_full.png",full_rgba) #mask_gray=lip_utils.create_gray(img_w,img_h) #lip_utils.copy_image(mask_gray,chin_mask_image_resized,box[0][0],box[0][1]) # chin mask is useless return full_rgba if __name__ == "__main__": # 画像ファイルのパス img_path = "straight.jpg" img = cv2.imread(img_path) img_h, img_w = lip_utils.get_image_size(img) landmarks_list = lip_utils.image_to_landmarks_list(img) # パラメータ margin = 4 open_size_y = 20 open_size_x = 0 # 関数の呼び出し process_chin_image(img,landmarks_list, margin, open_size_y, open_size_x)