face++人工智能批量抠图实现
调用face++ 的API实现批量抠图尝试
代码如下:
1 # -*- coding: utf-8 -*- 2 import os 3 import base64 4 import json 5 import requests 6 7 def read_picture(fpath): 8 flist = os.listdir(fpath) 9 return flist 10 11 def cutout(http_url,body,fpath,file): 12 files = {"image_file": open(fpath + file, "rb")} 13 resp = requests.post(http_url,body,files=files).content.decode('utf-8') 14 result = json.JSONDecoder().decode(resp) 15 img = result['body_image'] 16 imagedata = base64.b64decode(img) 17 return imagedata 18 19 def save_jpg(fpath,file,imagedata): 20 with open( fpath + 'new_'+ file,'wb') as f: 21 f.write(imagedata) 22 23 def main(): 24 fpath = r"你的图片所在路径" 25 http_url = '你调用的api地址' 26 body = {'api_key': '你的api_key', 'api_secret': '你的api_secret'} 27 flist = read_picture(fpath) 28 for file in flist: 29 imagedata = cutout(http_url, body,fpath ,file) 30 save_jpg(fpath,file, imagedata) 31 32 if __name__ == '__main__': 33 main()
posted on 2019-07-11 17:23 Cooper_73 阅读(1036) 评论(0) 编辑 收藏 举报