【发布时间】:2021-09-28 13:15:54
【问题描述】:
昨天我编辑了来自Microsoft Azure Face API Quickstart的代码,我可以在本地图像中识别人。
当我用多个图像训练一个组时,我得到了一个错误的请求异常,并且在检查图像之前我得到了一个错误的请求
Dictionary<string, string[]> personDictionary = new Dictionary<string, string[]>
{
{ "Jonas", new[] {"jonasTrain2.jpg"}},
{"Thomas", new [] {"thomasTrain1.jpg"}}
};
string sourceImageFilePath = @"C:\Users\jonas\Desktop\FAces\Test\jonasTest1.jpg";
Console.WriteLine($"Create a person group ({personGroupId}).");
await client.PersonGroup.CreateAsync(personGroupId, personGroupId, recognitionModel: recognitionModel);
foreach (var groupedFace in personDictionary.Keys)
{
await Task.Delay(250);
Person person = await client.PersonGroupPerson.CreateAsync(personGroupId: personGroupId, name: groupedFace);
Console.WriteLine($"Create a person group person '{groupedFace}'");
foreach (var similarImage in personDictionary[groupedFace])
{
Console.WriteLine($"Add face to the person group person ({groupedFace}) from image `{similarImage}`");
FileStream fs = File.OpenRead(TRAIN_PATH + @"\" + similarImage);
PersistedFace face = await client.PersonGroupPerson.AddFaceFromStreamAsync(personGroupId, person.PersonId,
fs, similarImage);
}
}
这是第一个带有训练 Bad Exeption 的代码示例,此代码可以工作,但是当我处理多个图像时,它就不起作用了。
Console.WriteLine();
List<Guid> sourceFaceIds = new List<Guid>();
List<DetectedFace> detectedFaces = await DetectFaceRecognize(client, sourceImageFilePath, recognitionModel);
foreach (var detectedFace in detectedFaces) sourceFaceIds.Add(detectedFace.FaceId.Value);
var idntifyResuluts = await client.Face.IdentifyAsync(sourceFaceIds, personGroupId);
foreach (var identifyResult in idntifyResuluts)
{
try
{
Person person = await client.PersonGroupPerson.GetAsync(personGroupId, identifyResult.Candidates[0].PersonId);
Console.WriteLine($"Person '{person.Name}' is identified for face in: {Path.GetFileName(sourceImageFilePath)} - {identifyResult.FaceId}," +
$" confidence: {identifyResult.Candidates[0].Confidence}");
}
catch (Exception)
{
}
这是我在这一行中得到异常的第二个代码示例:
var idntifyResuluts = await client.Face.IdentifyAsync(sourceFaceIds, personGroupId);
有人知道解决方案吗? 您可以在github找到孔代码
[更新]
我用多个图像修复了第一个异常。图片太大了。
【问题讨论】:
-
这里有很多代码,但很难准确理解你卡在哪里。哪一行代码失败了,您是否捕获了发送的原始有效负载,以便您可以通过 PostMan 等工具进行验证?
-
@ChrisSchaller 更新我解决了第一个问题(Azure 不喜欢 4k 图片)我在第 86 行 var idntifyResuluts = await client.Face.IdentifyAsync(sourceFaceIds, personGroupId);
-
@ChrisSchaller 试图做邮递员的事情,但我没有找到关于它的教程
-
您应该捕获异常并将详细信息粘贴到您的帖子的更新中。 Azure 服务和 SDK 通常会在响应中提供足够的详细信息,帮助您确定解决方案
-
@ChrisSchaller 谢谢你的意见我做了那个更新
标签: c# azure azure-cognitive-services face-api