/identity/selfie_watermark_verification

1.接口描述

该 API 的功能是将人脸照片与后台带水印照片进行比对,来判断是否同一个人。

  • 普通人脸照片要求:

    1. 格式为 JPG(JPEG),BMP,PNG,GIF,TIFF
    2. 宽和高大于 8px,小于等于4000px
    3. 小于等于 5 MB
  • 带水印照片要求:

    1. 格式为 JPG(JPEG),BMP,PNG,TIFF
    2. 宽和高大于 8px,小于等于 480px
    3. 小于等于 1 MB
  • 支持自动识别人脸方向
    1. 上传的图片中包含有 exif 方向信息,先按此信息旋转、翻转后再做识别人脸方向并调整
    2. 如果照片方向混乱且 exif 方向信息不存在或不正确,自动识别人脸方向并调整

请求方式:

POST

请求URL:

https://cloudapi.linkface.cn/identity/selfie_watermark_verification

2.请求参数

字段 类型 必需 描述
api_id string API 账户
api_secret string API 密钥
selfie_file file 见下方注释 人脸图片文件,上传本地图片进行检测时选取此参数
selfie_url string 见下方注释 人脸图片网络地址,采用抓取网络图片方式时需选取此参数
selfie_image_id string 见下方注释 人脸图片的id,在云端上传过图片可采用此参数
watermark_picture_file file 见下方注释 后台预留的带水印照片,上传本地图片进行检测时选取此参数
watermark_picture_url string 见下方注释 后台预留的带水印照片的网络地址,采用抓取网络图片方式时需选取此参数
watermark_picture_image_id string 见下方注释 后台预留的带水印照片的id,在云端上传过图片可采用
selfie_auto_rotate boolean 开启普通照片自动旋转功能。开通:true,不开通:false。默认不开通
watermark_auto_rotate boolean 开启网纹照片自动旋转功能。开通:true,不开通:false。默认不开通

参数 selfie_file , selfie_urlselfie_image_id 三选一。

参数 watermark_picture_file , watermark_picture_urlwatermark_picture_image_id 三选一。

若将 URL 放入 Query String 中则需要对特殊字符进行转义,所有中文和特殊字符必需以UTF-8编码转义。 目前支持 http/https 等协议的网络地址。下载限时 5s,超时后仍未下载完成则属于失败。 参数 selfie_filewatermark_picture_file 需把图片文件的内容以 multipart/form-data 的形式放到 POST 消息体中。

打开自动旋转功能会增加运算时间,请酌情考虑是否开通

3.返回参数

字段 类型 描述
request_id string 本次请求的id
status string 状态,正常为 OK,其他值表示失败,详见错误码
confidence float 置信度,值为 0~1,值越大表示两张照片是同一个人的可能性越大
watermark_picture object 使用file、url方式返回的预留的带水印照片的云端id
selfie object 使用file、url方式返回的普通人脸图片的云端id

当图片中存在多个人脸时,系统会选出其中最大的人脸进行比对。

置信度阈值与错误率对应关系:

阈值 0.4 0.5 0.6 0.7 0.8 0.9
错误率 十分之一 百分之一 千分之一 万分之一 十万分之一 百万分之一

注意:**人脸比对的阈值建议取万分之一,0.7附近,也可以根据风控等级上下微调**

{
  "request_id": "TID8bf47ab6eda64476973cc5f5b6ebf57e",
  "status": "OK",
  "confidence": 0.52071,
  "watermark_picture": { 
    "image_id": "xxxxx"
   },
  "selfie": { 
    "image_id": "xxxxx"
  }
}

4.错误码

状态码 status 字段 说明
400 ENCODING_ERROR 参数非UTF-8编码
400 DOWNLOAD_TIMEOUT 网络地址图片获取超时,详情见字段 image
400 DOWNLOAD_ERROR 网络地址图片获取失败,详情见字段 image
400 IMAGE_FILE_SIZE_TOO_BIG 图片体积过大 ,详情见字段 image
400 IMAGE_ID_NOT_EXIST 图片不存在,详情见字段 image
400 NO_FACE_DETECTED 图片未检测出人脸 ,详情见字段 image
400 CORRUPT_IMAGE 文件不是图片文件或已经损坏,详情见字段 image
400 INVALID_IMAGE_FORMAT_OR_SIZE 图片大小或格式不符合要求,详情见字段 image
400 INVALID_ARGUMENT 请求参数错误,具体原因见 reason 字段内容
401 UNAUTHORIZED 账号或密钥错误
401 KEY_EXPIRED 账号过期,具体情况见 reason 字段内容
403 RATE_LIMIT_EXCEEDED 调用频率超出限额
403 NO_PERMISSION 无调用权限
403 OUT_OF_QUOTA 调用次数超出限额
404 NOT_FOUND 请求路径错误
500 INTERNAL_ERROR 服务器内部错误
{
  "status": "DOWNLOAD_TIMEOUT",
  "image": "selfie",
  "request_id": "TID8bf47ab6eda64476973cc5f5b6ebf57e"
}

5.输入示例

  • cURL 样例
curl -X POST "https://cloudapi.linkface.cn/identity/selfie_watermark_verification?api_id=ID&api_secret=SECRET" \
  -F selfie_file=@/PATH/TO/IMAGE1 -F watermark_picture_file=@/PATH/TO/IMAGE2
  • HTTPie 样例
http -f POST "https://cloudapi.linkface.cn/identity/selfie_watermark_verification?api_id=ID&api_secret=SECRET" \
  selfie_file@/PATH/TO/IMAGE1 watermark_picture_file@/PATH/TO/IMAGE2
  • C++ 样例
#include <iostream>
#include <cstring>
#include <exception>
#include <curl/curl.h>
#include <json/json.h>

using namespace std;
size_t callback(char *ptr, size_t size, size_t nmemb, string &stream){

  size_t sizes = size*nmemb;
  string temp(ptr,sizes);
  stream += temp;
  return sizes;
}
int main( int argv, char * argc[] ){

  CURL *curl;
  CURLM *multi_handle;
  CURLcode res;
  long code;
  string stream;
  struct curl_httppost *formpost = NULL;
  struct curl_httppost *lastptr = NULL;
  struct curl_slist *headerlist = NULL;

  try{

    curl_global_init(CURL_GLOBAL_DEFAULT);
    curl = curl_easy_init();

    if( curl ){

      curl_formadd(&formpost,&lastptr,CURLFORM_COPYNAME,"api_id",
                  CURLFORM_COPYCONTENTS, "ID",CURLFORM_END);
      curl_formadd(&formpost,&lastptr,CURLFORM_COPYNAME,"api_secret",
                  CURLFORM_COPYCONTENTS, "SECRET",CURLFORM_END);
      curl_formadd(&formpost,&lastptr,CURLFORM_COPYNAME,"selfie_file",
                  CURLFORM_FILE, argc[1], CURLFORM_END);
      curl_formadd(&formpost,&lastptr,CURLFORM_COPYNAME,"watermark_picture_file",
                  CURLFORM_FILE, argc[2], CURLFORM_END);

      curl_easy_setopt(curl, CURLOPT_URL, "https://cloudapi.linkface.cn/identity/selfie_watermark_verification");
      curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
      curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);

      #ifdef SKIP_PEER_VERIFICATION
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
      #endif
      #ifdef SKIP_HOSTNAME_VERIFICATION
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
      #endif

      res = curl_easy_perform(curl);

      if( res != CURLE_OK ){
        cout<<"curl_easy_perform() failed:"<<curl_easy_strerror(res)<<endl;
        return -1;
      }
      curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
      Json::Value res_data;
      Json::Reader *reader = new Json::Reader(Json::Features::strictMode());
      if(!reader->parse(stream, res_data)){
        cout<<"parse error";
        return -1;
      }
      cout<<"HTTP Status Code:"<<code<<endl;
      cout<<res_data<<endl;
      curl_easy_cleanup(curl);
  }
    curl_global_cleanup();

  }catch(exception &ex){
    cout<<"curl exception:"<<ex.what()<<endl;
  }
}
  • Java 样例
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class httpClientPost {
      public static final String api_id = "ID"; 
      public static final String api_secret = "SECRET";
      public static final String filepath1="C:/Users/face.jpg";//图片1路径
      public static final String filepath2="C:/Users/card.jpg";//图片2路径
      public static final String POST_URL = "https://cloudapi.linkface.cn/identity/selfie_watermark_verification";

      public static void HttpClientPost() throws ClientProtocolException, IOException {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost post = new HttpPost(POST_URL);
            StringBody id = new StringBody(api_id);
            StringBody secret = new StringBody(api_secret);
            FileBody fileBody1 = new FileBody(new File(filepath1));
            FileBody fileBody2 = new FileBody(new File(filepath2));
            MultipartEntity entity = new MultipartEntity();
            entity.addPart("selfie_file", fileBody1);
            entity.addPart("watermark_picture_file", fileBody2);
            entity.addPart("api_id", id);
            entity.addPart("api_secret", secret);
            post.setEntity(entity);

            HttpResponse response = httpclient.execute(post);
            if (response.getStatusLine().getStatusCode() == 200) {
                HttpEntity entitys = response.getEntity();
                BufferedReader reader = new BufferedReader(
                    new InputStreamReader(entitys.getContent()));
                String line = reader.readLine();
                System.out.println(line);
            }else{
                HttpEntity r_entity = response.getEntity();
                String responseString = EntityUtils.toString(r_entity);
                System.out.println("错误码是:"+response.getStatusLine().getStatusCode()+"  "+response.getStatusLine().getReasonPhrase());
                System.out.println("出错原因是:"+responseString);
                //你需要根据出错的原因判断错误信息,并修改
            }

            httpclient.getConnectionManager().shutdown();
      }


    public static void main(String[] args) throws ClientProtocolException, IOException {
        HttpClientPost();
    }
}
  • Ruby 样例
require 'net/http/post/multipart'
require 'json'

begin
  uri = URI.parse('https://cloudapi.linkface.cn/identity/selfie_watermark_verification')
  req = Net::HTTP::Post::Multipart.new uri.path,
        "selfie_file" => UploadIO.new(File.new("./px.jpg"), "image/jpeg", "px.jpg"),
        "watermark_picture_file" => UploadIO.new(File.new("./px_test"), "image/jpeg", "px_test"),
        "api_id" => "ID",
        "api_secret" => "SECRET"
  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request(req)
  end
  result = JSON.parse(res.body)
  puts result
rescue Exception => e
  puts e.message
end
  • Python 样例

我们提供的样例支持 Python 2.7 & 3.4–3.7 和 PyPy,其他版本暂不提供,需要您查阅相关资料。

import requests

try:
    host = 'https://cloudapi.linkface.cn'
    url = host + '/identity/selfie_watermark_verification'
    files = {'selfie_file': open('/selfie/image/file/path', 'rb'), 'watermark_picture_file': open('/watermark/picture/file/path', 'rb')}
    data = {'api_id': 'ID','api_secret': 'SECRET'}

    response = requests.post(url, files = files, data = data)
    result = response.json()
    print result
except Exception as e:
    print("type error: " + str(e))
  • PHP 样例

我们提供的样例是基于 PHP 5.5 与 PHP 5.6 两个版本,其他版本暂不提供,需要您查阅相关资料。

以下样例是基于 PHP 5.5 版本的。

<?php
   $testurl = 'https://cloudapi.linkface.cn/identity/selfie_watermark_verification'; // url
   $selfiePath = 'C:/Users/face1.jpg';//自拍照路径
   $watermarkPath = 'C:/Users/face2.jpg';//水印照路径
   $selfieContent = '@' . realpath($selfiePath);
   $watermarkContent = '@' . realpath($watermarkPath);
   $post_data = array ('api_id' => 'ID','api_secret' => 'SECRET',
             'selfie_file' => $selfieContent,'watermark_picture_file' => $watermarkContent );
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $testurl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//您可以根据需要,决定是否打开SSL验证
   curl_setopt($ch, CURLOPT_POST,1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   $output = curl_exec($ch);
   var_dump($output);
   curl_close($ch);
?>

以下样例是基于 PHP 5.6 版本的。

<?php
   $testurl = 'https://cloudapi.linkface.cn/identity/selfie_watermark_verification'; // url
   $selfiePath = 'C:/Users/face1.jpg';//自拍照路径
   $watermarkPath = 'C:/Users/face2.jpg';//水印照路径
   $selfieContent = new \CURLFile($selfiePath);
   $watermarkContent = new \CURLFile($watermarkPath);
   $post_data = array ('api_id' => 'ID','api_secret' => 'SECRET',
             'selfie_file' => $selfieContent,'watermark_picture_file' => $watermarkContent );
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $testurl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//您可以根据需要,决定是否打开SSL验证
   curl_setopt($ch, CURLOPT_POST,1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   $output = curl_exec($ch);
   var_dump($output);
   curl_close($ch);
?>

results matching ""

    No results matching ""