首页 > 其他 > 详细

face++人工智能批量抠图实现

时间:2019-07-11 18:13:48      阅读:217      评论:0      收藏:0      [点我收藏+]

 

调用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()

 

face++人工智能批量抠图实现

原文:https://www.cnblogs.com/cooper-73/p/11171407.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!