请求URL:api/face_compare/v1
请求方式:POST
返回类型:JSON
参数 | 类型 | 说明 |
---|---|---|
Content-type | string | application/json |
APIKEY | string | 您的API KEY |
参数 | 是否必填 | 类型 | 说明 |
---|---|---|---|
image_base64_1 | 必填 | string | base64编码的图片文件 |
image_base64 | 必填 | string | base64编码的图片文件 |
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 = '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)
$url = "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);
import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Base64; import java.util.Map; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; public class FaceCompareExample { private static final String API_KEY = "******"; // 你的API KEY private static final String FILE_PATH_1 = "..."; // 图片1路径 private static final String FILE_PATH_2 = "..."; // 图片2路径 private static final String API_URL = "api/face_compare/v1"; public static void main(String[] args) throws IOException { String b64_1 = getBase64(FILE_PATH_1); String b64_2 = getBase64(FILE_PATH_2); MaprequestBody = Map.of( "image_base64_1", b64_1, "image_base64_2", b64_2 ); try (CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpPost request = new HttpPost(API_URL); request.setHeader("APIKEY", API_KEY); request.setHeader("Content-Type", "application/json"); request.setEntity(new StringEntity(new Gson().toJson(requestBody))); try (CloseableHttpResponse response = httpClient.execute(request)) { HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); Map jsonResponse = new Gson().fromJson(responseBody, new TypeToken
参数 | 说明 |
---|---|
code | 错误码 |
msg | 错误信息(英文) |
msg_cn | 错误信息(中文) |
score | 比对得分,推荐80分作为阈值,80分以上可以判断为同一人,(当code==0时会有该返回值) |
错误码 | 说明 |
---|---|
0 | 成功 |
1 | 图片错误 |
2 | 处理错误 |
3 | 服务器繁忙 |
4 | 参数错误,具体错误看msg或msg_cn |
5 | 未知错误 |
101 | API-KEY不正确 |
102 | 未知用户 |
103 | 积分已用完 |
104 | 扣除积分失败 |
人脸对比接口(API)采用自研深度学习算法与图像处理技术,实现两张人脸照片之间相似度比对的技术服务。它能够精准、高效地识别人脸特征,并计算出两张人脸照片的相似度评分,广泛应用于身份验证、安全监控、用户登录等场景。
1. 人脸特征提取
人脸对比接口可以从上传的人脸照片中提取独特的面部特征点,生成可供比对的特征向量。
2. 相似度计算
通过比对两张照片的特征向量,API能够计算出它们的相似度评分,确定两张照片是否属于同一个人。
3. 多种输入格式支持
支持多种图片格式(如JPEG、PNG、BMP等)的输入,适应不同应用场景的需求。
4. 实时处理
API具有高效的处理能力,能够在毫秒级时间内完成对比,适合实时性要求高的应用场景。
API类型 | 价格说明 |
---|---|
人脸对比接口API | 每次调用消耗一积分 |
如有问题联系右侧“客服” |