注册申请无需多说
代码如下 具体解释注释在代码中,如有疑问欢迎留言讨论。
import requests from json import JSONDecoder import base64 import time #下面是进行图像分割的API http_url = "https://api-cn.faceplusplus.com/humanbodypp/v2/segment" key = "*********************" #更改成自己的密匙及密码即可 secret = "********************" for i in range(0,100): filepath = r'indian\\'+ str(i) +'.jpg' #为了方便我将文件命名为1.jpg,2.jpg......如不同自行更改循环以及路径 data = {"api_key": key, "api_secret": secret, "return_landmark": "1"} files = {"image_file": open(filepath, "rb")} response = requests.post(http_url, data=data, files=files) req_con = response.content.decode('utf-8') req_dict = JSONDecoder().decode(req_con) result = req_dict['result'] imgdata = base64.b64decode(result) file = open('Face_indian_mask\\'+str(i)+'_mask.jpg','wb') #这里是输出的路径及文件名 file.write(imgdata) file.close() print("next is :"+str(i+1)) time.sleep(10) #由于使用的是免费试用版的API所以有流量限制,所以设置sleep,如果半路程序充值更改循环起点重新开始即可(注意Face要求的图片大小限制)