|
""" |
|
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 |
|
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]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
mask = lip_utils.create_mask_from_points(cropped,cropped_jaw_points,4,2) |
|
if lip_utils.DEBUG_CHIN: |
|
cv2.imwrite("chin_mask.jpg",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) |
|
|
|
|
|
|
|
if lip_utils.DEBUG_CHIN: |
|
cv2.imwrite("chin_resized.png",chin_image_resized) |
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
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) |