forked from Zeyi-Lin/HivisionIDPhotos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakeBeautiful.py
45 lines (43 loc) · 1.78 KB
/
MakeBeautiful.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
@author: cuny
@file: MakeBeautiful.py
@time: 2022/7/7 20:23
@description:
美颜工具集合文件,作为暴露在外的插件接口
"""
from .GrindSkin import grindSkin
from .MakeWhiter import MakeWhiter
from .ThinFace import thinFace
import numpy as np
def makeBeautiful(input_image: np.ndarray,
landmark,
thinStrength: int,
thinPlace: int,
grindStrength: int,
whiterStrength: int
) -> np.ndarray:
"""
美颜工具的接口函数,用于实现美颜效果
Args:
input_image: 输入的图像
landmark: 瘦脸需要的人脸关键点信息,为 fd68 返回的第二个参数
thinStrength: 瘦脸强度,为 0-10(如果更高其实也没什么问题),当强度为 0 或者更低时,则不瘦脸
thinPlace: 选择瘦脸区域,为 0-2 之间的值,越大瘦脸的点越靠下
grindStrength: 磨皮强度,为 0-10(如果更高其实也没什么问题),当强度为 0 或者更低时,则不磨皮
whiterStrength: 美白强度,为 0-10(如果更高其实也没什么问题),当强度为 0 或者更低时,则不美白
Returns:
output_image 输出图像
"""
try:
_, _, _ = input_image.shape
except ValueError:
raise TypeError("输入图像必须为 3 通道或者 4 通道!")
# 三通道或者四通道图像
# 首先进行瘦脸
input_image = thinFace(input_image, landmark, place=thinPlace, strength=thinStrength)
# 其次进行磨皮
input_image = grindSkin(src=input_image, strength=grindStrength)
# 最后进行美白
makeWhiter = MakeWhiter()
input_image = makeWhiter.run(input_image, strength=whiterStrength)
return input_image