cooper-73

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

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-06-01
  • 2021-11-10
  • 2021-11-26
  • 2021-12-10
  • 2021-12-04
  • 2021-08-14
  • 2021-12-22
猜你喜欢
  • 2021-12-14
  • 2021-12-30
  • 2021-11-17
  • 2021-12-16
  • 2021-07-30
  • 2021-12-06
  • 2021-08-03
相关资源
相似解决方案