Step By Step
1、API官方说明
2、Open API Exployer使用快速开始
3、老版本NET SDK安装及使用
4、新版本NET SDK安装及使用
1、CompareFace API官方说明
人脸比对1:1
2、Open API Exployer使用快速开始
快速测试地址:CompareFace
3、老版本NET SDK安装及使用
- 3.1 nuget安装sdk:aliyun-net-sdk-facebody
- 3.2 Code Sample
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using System;
namespace ConsoleApp9
{
class Program
{
static void Main(string[] args)
{
IClientProfile profile = DefaultProfile.GetProfile("cn-shanghai", "<accesskey>", "<accesssecret>");
DefaultAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.Method = MethodType.POST;
request.Domain = "facebody.cn-shanghai.aliyuncs.com";
request.Version = "2019-12-30";
request.Action = "CompareFace";
// request.Protocol = ProtocolType.HTTP;
request.AddQueryParameters("QualityScoreThreshold", "60");
request.AddQueryParameters("ImageURLA", "https://taro-tensorflow.oss-cn-shanghai.aliyuncs.com/face/jingtian1.jpeg");
request.AddQueryParameters("ImageURLB", "https://taro-tensorflow.oss-cn-shanghai.aliyuncs.com/face/jingtian2.jpeg");
try
{
CommonResponse response = client.GetCommonResponse(request);
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
}
catch (ServerException e)
{
Console.WriteLine(e);
}
catch (ClientException e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
}
- 3.3 Result
{"RequestId":"FADC78F0-5C94-522E-B089-43AD********","Data":{"QualityScoreA":99.9901123046875,"QualityScoreB":95.234146118164062,"Thresholds":[61.0,69.0,75.0],"Confidence":83.987808227539062,"RectAList":[175,107,177,222],"RectBList":[167,76,170,219]}}
4、新版本NET SDK安装及使用
- 4.1 nuget安装sdk:AlibabaCloud.SDK.Facebody20191230
- 4.2 Code Sample
using AlibabaCloud.SDK.Facebody20191230.Models;
using System;
namespace ConsoleApp10
{
class Program
{
public static AlibabaCloud.SDK.Facebody20191230.Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// 您的AccessKey ID
AccessKeyId = accessKeyId,
// 您的AccessKey Secret
AccessKeySecret = accessKeySecret,
};
// 访问的域名
config.Endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new AlibabaCloud.SDK.Facebody20191230.Client(config);
}
static void Main(string[] args)
{
AlibabaCloud.SDK.Facebody20191230.Client client = CreateClient("<accesskey>", "<accesssecret>");
CompareFaceRequest compareFaceRequest = new CompareFaceRequest
{
QualityScoreThreshold = 60f,
ImageURLA = "https://taro-tensorflow.oss-cn-shanghai.aliyuncs.com/face/jingtian1.jpeg",
ImageURLB = "https://taro-tensorflow.oss-cn-shanghai.aliyuncs.com/face/jingtian2.jpeg",
};
// 复制代码运行请自行打印 API 的返回值
CompareFaceResponse compareFaceResponse = client.CompareFace(compareFaceRequest);
Console.WriteLine(compareFaceResponse.Body.Data.RectAList.Count);
Console.WriteLine(compareFaceResponse.Body.Data.Confidence);
Console.ReadKey();
}
}
}
- 4.3 Result
4
83.98781