自学内容网 自学内容网

Face++API调用

人脸检测API调用 

import requests
import json
#将自己的KEY和Secret进行替换
API_KEY='your_API_KET'  
API_SECRET='your_API_Secret'

# 人脸识别的URL
URL = 'https://api-cn.faceplusplus.com/facepp/v3/detect'

# 请求参数,需要什么参数传入什么参数
data = {"api_key":API_KEY, 
        "api_secret":API_SECRET, 
        "image_url":'https://ts1.cn.mm.bing.net/th?id=OIP-C.Lc7aekOkY0t0Fii9a_xzYwHaK3&w=115&h=150&c=8&rs=1&qlt=90&o=6&dpr=1.3&pid=3.1&rm=2',
        #期望返回的参数
        "return_attributes": "gender,age,smiling,beauty",
        #  return_landmark 不写默认是不返回检测点,1为返回83个人脸检测点,2为返回106个检测点       
        "return_landmark":1}
# 发送请求
response = requests.post(URL,data=data)
req_con = response
print(req_con)
req_con = response.json()
print(req_con)

运行结果截图:

人脸美颜API调用
from PIL import Image
import base64
import io
import requests
import json

#将自己的KEY和Secret进行替换
API_KEY='your_API_KET'  
API_SECRET='your_API_Secret'

# 人脸美颜的URL
URL = 'https://api-cn.faceplusplus.com/facepp/v1/beautify'

# 请求参数,需要什么参数传入什么参数
data = {"api_key":API_KEY, 
        "api_secret":API_SECRET, 
        "image_url":'https://ts1.cn.mm.bing.net/th?id=OIP-C.Lc7aekOkY0t0Fii9a_xzYwHaK3&w=115&h=150&c=8&rs=1&qlt=90&o=6&dpr=1.3&pid=3.1&rm=2',
        "whitening":80,
        "smoothing":80
       }
# 发送请求
response = requests.post(URL,data=data)
req_con = response
print(req_con)
req_con = response.json()
print(req_con)
#获取美颜后的照片
base64_str=req_con['result']

image_data = base64.b64decode(base64_str)
image = Image.open(io.BytesIO(image_data))
image.save("output.jpg")

 人脸对比

import requests
import json

#将自己的KEY和Secret进行替换
API_KEY='your_API_KET'  
API_SECRET='your_API_Secret'

# 人脸对比的URL
URL = 'https://api-cn.faceplusplus.com/facepp/v3/compare'

# 请求参数,需要什么参数传入什么参数
data = {"api_key":API_KEY, 
        "api_secret":API_SECRET, 
        "image_url1":'https://ts1.cn.mm.bing.net/th?id=OIP-C.Lc7aekOkY0t0Fii9a_xzYwHaK3&w=115&h=150&c=8&rs=1&qlt=90&o=6&dpr=1.3&pid=3.1&rm=2',
        "image_url2":'https://ts1.cn.mm.bing.net/th/id/R-C.717bfafeb2991c64790c4e89bbea5bda?rik=QOqbwamEroQU9A&riu=http%3a%2f%2fa2.att.hudong.com%2f51%2f28%2f01300001066597135114289686481.jpg&ehk=Ku6dkcMh2Cg3oX0YFkXs7VBs2UA54B0DzFY0mqN117g%3d&risl=&pid=ImgRaw&r=0'
        
       }
# 发送请求
response = requests.post(URL,data=data)
req_con = response
print(req_con)
req_con = response.json()
print(req_con)


原文地址:https://blog.csdn.net/ylycrp/article/details/142410966

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!