File size: 1,145 Bytes
6ed4a9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
from PIL import Image
from head_extractor import ProcessorPipeline

print("--- 开始测试 head_extractor 包 ---")

# 1. 初始化 Pipeline
print("正在加载模型...")

pipeline = ProcessorPipeline.load()
print("模型加载成功!")


# 2. 读取一张待处理的图片 (请确保图片路径正确)
image_path = "./assets/001.jpg" # 示例图片路径
print(f"正在打开图片: {image_path}")
input_image = Image.open(image_path)


# 3. 提取头部
print("正在提取头部...")
# case:1
# default pad2square=True, output_mode='RGB'
extracted_head_image_rgb = pipeline.extract_head(input_image, output_mode='RGB')
extracted_head_image_rgb.save("./assets/001_head-default.webp")

# case:2
# pad2square=False
# rgba
result_rgba = pipeline.extract_head(
    input_image,
    output_mode='RGBA',
    pad2square=False
)
result_rgba.save("./assets/001_head-pad2square-false.webp")

# case:3
# black bg
result_black_bg = pipeline.extract_head(
    input_image,
    background_color=(0, 0, 0),
    pad2square=True,
    output_mode='RGB'
)
result_black_bg.save("./assets/001_head-black-bg.webp")



print(f"处理完成!结果已保存")