请求URL:https://api.shiliuai.com/api/face_compare/v1
请求方式:POST
请求参数-请求头(Header):
参数 | 类型 | 说明 |
---|---|---|
Content-Type | string | application/json |
APIKEY | string | 您的API KEY |
请求参数-请求内容(Body):
参数 | 类型 | 说明 |
---|---|---|
image_base64_1 | string, required | base64编码的图片文件 |
image_base64_2 | string, required | base64编码的图片文件 |
参数 | 说明 |
---|---|
code | 错误码 |
msg | 错误信息(英文) |
msg_cn | 错误信息(中文) |
score | 比对得分,推荐80分作为阈值,80分以上可以判断为同一人,(当code==0时会有该返回值) |
错误码说明:
错误码 | 说明 |
---|---|
0 | 成功 |
1 | 图片错误 |
2 | 处理错误 |
3 | 服务器繁忙 |
4 | 参数错误,具体错误看msg或msg_cn |
5 | 未知错误 |
101 | API-KEY不正确 |
102 | 未知用户 |
103 | 积分已用完 |
104 | 扣除积分失败 |
Python 代码示例:
import requests import base64 import cv2 import json import numpy as np def get_base64(file_path): with open(file_path, 'rb') as fp: b64 = base64.b64encode(fp.read()).decode('utf8') return b64 api_key = '******' # 你的API KEY file_path_1 = '...' # 图片1路径 file_path_2 = '...' # 图片2路径 b64_1 = get_base64(file_path_1) b64_2 = get_base64(file_path_2) url = 'https://api.shiliuai.com/api/face_compare/v1' headers = {'APIKEY': api_key, "Content-Type": "application/json"} data = { "image_base64_1": b64_1, "image_base64_2": b64_2 } response = requests.post(url=url, headers=headers, json=data) response = json.loads(response.content) print(response)
PHP 代码示例:
$url = "https://api.shiliuai.com/api/face_compare/v1"; $method = "POST"; $apikey = "******"; $header = array(); array_push($header, "APIKEY:" . $apikey); array_push($header, "Content-Type:application/json"); function get_base64($file_path) { $handle = fopen($file_path, "r"); $image = fread($handle, filesize($file_path)); fclose($handle); $image_base64 = base64_encode($image); return image_base64; } $file_path_1 = "..."; $image_base64_1 = get_base64($file_path_1); $file_path_2 = "..."; $image_base64_2 = get_base64($file_path_2); $data = array( "image_base64_1"=> $image_base64_1, "image_base64_2"=> $image_base64_2 ); $post_data = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); $response = curl_exec($curl); var_dump($response);