Skip to main content
 首页 » 编程设计

c#之处理 SkyBiometry API

2024年02月20日20lyhabc

我需要比较两张照片的相似度。例如儿子和父亲的照片,并返回他们相似度的百分比。我用于 SkyBiometry.Client.FC。 API 返回的结果有问题。在所有识别的情况下,我得到 60%-68% 的相似性(阈值)。 最后我尝试比较两张相同的图片并得到 54% 的结果。我很困惑。我做错了什么?这是我的代码:

var client = new FCClient("my client id", "my client secret"); 
 
            var path = Server.MapPath("~/Content/Upload/1"); 
 
            var ids = new List<string> { "my client id" }; 
            var urls = new List<string>(); 
 
            Stream firstPicStream = System.IO.File.OpenRead(Path.Combine(path, "me.jpg")); 
            Stream secondPicStream = System.IO.File.OpenRead(Path.Combine(path, "me.jpg")); 
 
            var result1 = client.Faces.EndDetect(client.Faces.BeginDetect(null, new Stream[] { firstPicStream }, Detector.Aggressive, Attributes.Default, null, null)); 
            var result2 = client.Faces.EndDetect(client.Faces.BeginDetect(null, new Stream[] { secondPicStream }, Detector.Aggressive, Attributes.Default, null, null)); 
 
            urls.Add(result1.Photos[0].Url); 
            urls.Add(result2.Photos[0].Url); 
 
            var tags1 = result1.Photos[0].Tags; 
            var tags2 = result2.Photos[0].Tags; 
            var tagsIds = tags1.Select(tag => tag.TagId).ToList(); 
            tagsIds.AddRange(tags2.Select(tag => tag.TagId)); 
 
            var tagSaveResponce = client.Tags.EndSave(client.Tags.BeginSave(tagsIds, "My Namespace", "label", null, null)); 
 
            var recognizeResult = client.Faces.EndRecognize(client.Faces.BeginRecognize(ids, urls, null, "My Namespace", Detector.Aggressive, Attributes.Default, null, null)); 

请您参考如下方法:

您是否在为您为其保存新标签的用户调用 faces/train after tags/save?因为如果不这样做,您将仅使用旧用户标签执行识别。 另请注意,用户 ID 不能有空格,请确保检查 FCResponse.Status 属性是否存在可能的错误。