upload
Browse files- get_artist_pic_from_danbooru.py +67 -0
- get_artist_pic_from_yande.py +67 -0
get_artist_pic_from_danbooru.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
from pathlib import Path
|
3 |
+
from waifuc.action import (
|
4 |
+
HeadCountAction,
|
5 |
+
NoMonochromeAction,
|
6 |
+
FilterSimilarAction,
|
7 |
+
TaggingAction,
|
8 |
+
PersonSplitAction,
|
9 |
+
FaceCountAction,
|
10 |
+
FirstNSelectAction,
|
11 |
+
CCIPAction,
|
12 |
+
ModeConvertAction,
|
13 |
+
ClassFilterAction,
|
14 |
+
RandomFilenameAction,
|
15 |
+
AlignMinSizeAction
|
16 |
+
)
|
17 |
+
from waifuc.export import SaveExporter
|
18 |
+
from waifuc.source import DanbooruSource
|
19 |
+
|
20 |
+
|
21 |
+
def get_args():
|
22 |
+
parser = argparse.ArgumentParser()
|
23 |
+
normalized_filepath = lambda filepath: str(Path(filepath).absolute().as_posix())
|
24 |
+
|
25 |
+
parser.add_argument("--path", type = normalized_filepath, default = None, help = "爬取文件的保存路径")
|
26 |
+
# parser.add_argument("--dl-path", type = normalized_filepath, default = None, help = "下载图片路径")
|
27 |
+
parser.add_argument("--tag", type=str, nargs='+', help="爬取的图片标签")
|
28 |
+
parser.add_argument("--count", type = int, default = 1000, help = "爬取的图片数量")
|
29 |
+
|
30 |
+
return parser.parse_args()
|
31 |
+
|
32 |
+
|
33 |
+
def main():
|
34 |
+
arg = get_args()
|
35 |
+
|
36 |
+
if arg.path is None:
|
37 |
+
print("未输入保存路径")
|
38 |
+
return
|
39 |
+
else:
|
40 |
+
path = arg.path
|
41 |
+
|
42 |
+
if arg.tag is None:
|
43 |
+
print("未输入爬取的图片标签")
|
44 |
+
return
|
45 |
+
else:
|
46 |
+
tag = arg.tag
|
47 |
+
|
48 |
+
count = int(arg.count)
|
49 |
+
|
50 |
+
print(f"爬取的 Tag: {tag}")
|
51 |
+
print(f"爬取的图片数量: {count}")
|
52 |
+
print(f"保存路径: {path}")
|
53 |
+
|
54 |
+
source = DanbooruSource(tag)
|
55 |
+
source.attach(
|
56 |
+
HeadCountAction(1), # only 1 head,
|
57 |
+
ModeConvertAction('RGB', 'white'), # 以RGB色彩模式加载图像并将透明背景替换为白色背景
|
58 |
+
ClassFilterAction(['illustration', 'bangumi']), # 丢弃漫画或3D图像
|
59 |
+
FilterSimilarAction('all'), # 丢弃相似或重复的图像
|
60 |
+
)[:count].export(
|
61 |
+
SaveExporter(path)
|
62 |
+
)
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
if __name__ == '__main__':
|
67 |
+
main()
|
get_artist_pic_from_yande.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
from pathlib import Path
|
3 |
+
from waifuc.action import (
|
4 |
+
HeadCountAction,
|
5 |
+
NoMonochromeAction,
|
6 |
+
FilterSimilarAction,
|
7 |
+
TaggingAction,
|
8 |
+
PersonSplitAction,
|
9 |
+
FaceCountAction,
|
10 |
+
FirstNSelectAction,
|
11 |
+
CCIPAction,
|
12 |
+
ModeConvertAction,
|
13 |
+
ClassFilterAction,
|
14 |
+
RandomFilenameAction,
|
15 |
+
AlignMinSizeAction
|
16 |
+
)
|
17 |
+
from waifuc.export import SaveExporter
|
18 |
+
from waifuc.source import YandeSource
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
def get_args():
|
23 |
+
parser = argparse.ArgumentParser()
|
24 |
+
normalized_filepath = lambda filepath: str(Path(filepath).absolute().as_posix())
|
25 |
+
|
26 |
+
parser.add_argument("--path", type = normalized_filepath, default = None, help = "爬取文件的保存路径")
|
27 |
+
# parser.add_argument("--dl-path", type = normalized_filepath, default = None, help = "下载图片路径")
|
28 |
+
parser.add_argument("--tag", type=str, nargs='+', help="爬取的图片标签")
|
29 |
+
parser.add_argument("--count", type = int, default = 1000, help = "爬取的图片数量")
|
30 |
+
|
31 |
+
return parser.parse_args()
|
32 |
+
|
33 |
+
|
34 |
+
def main():
|
35 |
+
arg = get_args()
|
36 |
+
|
37 |
+
if arg.path is None:
|
38 |
+
print("未输入保存路径")
|
39 |
+
return
|
40 |
+
else:
|
41 |
+
path = arg.path
|
42 |
+
|
43 |
+
if arg.tag is None:
|
44 |
+
print("未输入爬取的图片标签")
|
45 |
+
return
|
46 |
+
else:
|
47 |
+
tag = arg.tag
|
48 |
+
|
49 |
+
count = int(arg.count)
|
50 |
+
|
51 |
+
print(f"爬取的 Tag: {tag}")
|
52 |
+
print(f"爬取的图片数量: {count}")
|
53 |
+
print(f"保存路径: {path}")
|
54 |
+
|
55 |
+
source = YandeSource(tag)
|
56 |
+
source.attach(
|
57 |
+
HeadCountAction(1), # only 1 head,
|
58 |
+
ModeConvertAction('RGB', 'white'), # 以RGB色彩模式加载图像并将透明背景替换为白色背景
|
59 |
+
ClassFilterAction(['illustration', 'bangumi']), # 丢弃漫画或3D图像
|
60 |
+
FilterSimilarAction('all'), # 丢弃相似或重复的图像
|
61 |
+
)[:count].export(
|
62 |
+
SaveExporter(path)
|
63 |
+
)
|
64 |
+
|
65 |
+
|
66 |
+
if __name__ == '__main__':
|
67 |
+
main()
|