tongchenkeji 发表于:2023-3-28 15:22:000次点击 已关注取消关注 关注 私信 你好,视觉智能平台非上海oss,在搜索人脸的时候,能不能给一个c#代码片段?[视觉智能开放平台] 暂停朗读为您朗读 你好,视觉智能平台非上海oss,在搜索人脸的时候,能不能给一个c#代码片段? 「点点赞赏,手留余香」 赞赏 还没有人赞赏,快来当第一个赞赏的人吧! 海报 视觉智能开放平台# C77# 对象存储1210# 视觉智能开放平台3859
xin在这AM 2023-11-28 8:02:34 1 看下这个最佳实践,有c#的代码 https://help.aliyun.com/document_detail/478011.html?spm=a2c4g.11186623.0.0.50815c27XwmY6T,此回答整理自钉群“阿里云视觉智能开放平台咨询1群”
叶秋学长AM 2023-11-28 8:02:34 2 当然可以,以下是使用视觉智能平台进行人脸搜索的C#代码示例: csharp using System; using System.Collections.Generic; using System.IO; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json; namespace BaiApiDemo { class Program { static void Main(string[] args) { string apiKey = “YOUR_API_KEY”; string apiSecret = “YOUR_API_SECRET”; string accessToken = GetAccessToken(apiKey, apiSecret); string url = "https://www.www.tongchenyun.com/wp-content/uploads/aliyun/2023/1128/search; string imageBase64 = Convert.ToBase64String(File.ReadAllBytes(your_image_path.jpg")); string imageType = "BASE64"; string groupIdList = "your_group_id_list"; // 多个用逗号隔开 int maxUserNum = 1; string faceType = "LIVE"; string qualityControl = "NONE"; string livenessControl = "NONE"; Dictionary dict = new Dictionary(); dict.Add("image", imageBase64); dict.Add("image_type", imageType); dict.Add("group_id_list", groupIdList); dict.Add("max_user_num", maxUserNum); dict.Add("face_type", faceType); dict.Add("quality_control", qualityControl); dict.Add("liveness_control", livenessControl); string content = JsonConvert.SerializeObject(dict); StringContent httpContent = new StringContent(content, Encoding.UTF8); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = httpClient.PostAsync(url, httpContent).Result; if (response.IsSuccessStatusCode) { string responseContent = response.Content.ReadAsStringAsync().Result; Console.WriteLine(responseContent); } else { Console.WriteLine("Response error: " + response.StatusCode); } Console.ReadLine(); } static string GetAccessToken(string apiKey, string apiSecret) { string url = $"https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={apiKey}&client_secret={apiSecret}"; HttpClient httpClient = new HttpClient(); HttpResponseMessage response = httpClient.GetAsync(url).Result; if (response.IsSuccessStatusCode) { string responseContent = response.Content.ReadAsStringAsync().Result; dynamic jsonResult = JsonConvert.DeserializeObject(responseContent); string accessToken = jsonResult.access_token; return accessToken; } else { throw new Exception("Failed to get access token from Baidu API"); } }} } 请将上述代码中的 YOUR_API_KEY 和 YOUR_API_SECRET 替换为您自己的百度API Key和Secret。另外,请将 your_image_path.jpg 替换为您要搜索的人脸图像路径, your_group_id_list 替换为您已经创建的人脸库ID。
游客7inutucukdxt6AM 2023-11-28 8:02:34 3 文件在本地或文件不在同一地域OSS,可以看下人脸搜索的最佳实践文档,有详细的C#调用代码。https://help.aliyun.com/document_detail/478011.htm
看下这个最佳实践,有c#的代码 https://help.aliyun.com/document_detail/478011.html?spm=a2c4g.11186623.0.0.50815c27XwmY6T,此回答整理自钉群“阿里云视觉智能开放平台咨询1群”
当然可以,以下是使用视觉智能平台进行人脸搜索的C#代码示例:
csharp using System; using System.Collections.Generic; using System.IO; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json;
namespace BaiApiDemo { class Program { static void Main(string[] args) { string apiKey = “YOUR_API_KEY”; string apiSecret = “YOUR_API_SECRET”; string accessToken = GetAccessToken(apiKey, apiSecret);
} 请将上述代码中的 YOUR_API_KEY 和 YOUR_API_SECRET 替换为您自己的百度API Key和Secret。另外,请将 your_image_path.jpg 替换为您要搜索的人脸图像路径, your_group_id_list 替换为您已经创建的人脸库ID。
文件在本地或文件不在同一地域OSS,可以看下人脸搜索的最佳实践文档,有详细的C#调用代码。https://help.aliyun.com/document_detail/478011.htm