功能描述
為個體新增一組人臉圖片,一個個體最多允許包含20張人臉圖片。關於參數的說明,請參見新增人臉API文檔。
您需要使用Alibaba Content Security Service的API接入地址,調用本SDK介面。關於API接入地址的資訊,請參見接入地址(Endpoint)。
新增人臉圖片任務
using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;
namespace csharp_sdk_sample
{
class Program
{
static void Main(string[] args)
{
/**
* 常見擷取環境變數方式:
* 擷取RAM使用者AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
* 擷取RAM使用者AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
*/
DefaultProfile profile = DefaultProfile.GetProfile(
"cn-shanghai",
"建議從環境變數中擷取RAM使用者AccessKey ID",
"建議從環境變數中擷取RAM使用者AccessKey Secret");
// 注意:此處執行個體化的client儘可能重複使用,提升檢測效能。避免重複建立串連。
DefaultAcsClient client = new DefaultAcsClient(profile);
AddFacesRequest request = new AddFacesRequest();
request.AcceptFormat = FormatType.JSON;
request.ContentType = FormatType.JSON;
request.Method = MethodType.POST;
request.Encoding = "UTF-8";
/**
* personId:使用者自訂個體ID,必填。
* urls:人臉圖片URL。
*/
Dictionary<string, object> httpBody = new Dictionary<string, object>();
httpBody.Add("personId", "個體ID");
httpBody.Add("urls", new List<string> { "人臉圖片連結地址1", "人臉圖片連結地址2" });
request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
try
{
AddFacesResponse response = client.GetAcsResponse(request);
if (response.HttpResponse.Status != 200)
{
Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
}
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
}
catch (Exception ex)
{
Console.WriteLine("Failed with error info: {0}", ex.Message);
}
}
}
}