最近看了很多关于AI方面的东西, 要想弄懂原理,还是很头痛的。使用飞架开源的这个套件,使用起来蛮简单的, 但是使用它默认的模型,图片的要求还是蛮高的, 最好是证件照,不然一般的图片,动漫化之后,太鬼畜了[捂脸]。转换源码 基于飞桨套件ppgan,批量头像动漫化,实现如下:# 运行前需要安装些依赖 # pip install ppgan # pip install cmake # pip install dlib # 批量头像动漫化 from ppgan.apps import Photo2CartoonPredictor import os import cv2 def photos2Cartoon(target_dir): p2c = Photo2CartoonPredictor() file_list = os.listdir(target_dir) for file in file_list: try: image_path = os.path.join(target_dir, file) cartoon = p2c.run(image_path) cartoon_save_path = os.path.join(p2c.output_path, file) cv2.imwrite(cartoon_save_path, cv2.cvtColor(cartoon, cv2.COLOR_RGB2BGR)) except Exception as e: pass if __name__ == "__main__": # 要动画化人像图片的目录位置 fileDir = "/Users/xxx/Desktop/workspace/study/paddlepaddle/source_imgs" # 人脸转卡通 photos2Cartoon(fileDir)转换结果 转换结果感觉还行,就是对图片要求挺高了, 最好是不带眼镜的证件照。下面是挑选了一些明星头像转换的动漫头像,你能猜出是谁么[呲牙]