【发布时间】:2019-05-23 22:40:06
【问题描述】:
当我在控制台中打印以下错误时,我正在关注 this documentation 在 Visual Studio 中使用 Microsoft Face API 来识别图像中的人脸:
将 Person 添加到“Microsoft.ProjectOxford.Face.FaceAPIException”类型的组异常时出错。
调用以下将人员添加到现有人员组的函数时会打印异常:
public async void AddPersonToGroup(string personGroupId, string name, string pathImage){
try{
await faceServiceClient.GetPersonGroupAsync(personGroupId);
CreatePersonResult person = await faceServiceClient.CreatePersonAsync(personGroupId, name);
foreach (var imgPath in Directory.GetFiles(pathImage, "*.jpg")) {
using (Stream s = File.OpenRead(imgPath)) {
await faceServiceClient.AddPersonFaceAsync(personGroupId, person.PersonId, s);
}
}
} catch (Exception ex){
//Below is where the error was printed.
Console.WriteLine("Error adding Person to Group " + ex.Message);
}
}
这就是我在 main 方法中调用 AddPersonToGroup 的方式:
new Program().AddPersonToGroup("actor", "Tom Cruise", @"C:\Users\ishaa\Documents\Face_Pictures\Tom_Cruise\");
我尝试在 Google 中搜索此错误并遇到 this SO question,但该答案对我不起作用。 (他们的答案是为FaceServiceClient 构造函数传递订阅密钥和端点。)
谁能提供有关此错误发生原因的任何见解?我一直无法弄清楚是什么原因造成的,但我相信它可能与
await faceServiceClient.GetPersonGroupAsync(personGroupId);。我还读到这可能是由于我选择了认知服务定价计划。然而,我正在使用的免费的允许每分钟 20 次交易,我只是想为 3 个不同的人添加 9 张图片。
【问题讨论】:
-
检查您尝试创建的内容是否已经存在
-
感谢尼科西的反馈。这是我第一次使用 Microsoft Azure。有没有机会,您知道我如何在 Azure 门户中查看现有的人员组吗?我创建了一个名为 Facial Recognition 的资源,我用它来获取密钥。是否有一个部分可以让我查看该信息,因为
Activity log似乎不包含它? -
为了帮助你,我们需要知道抛出了什么样的异常。当您捕获异常并获取更多详细信息时,您可以看看吗?放一个断点,看看你的
ex对象 -
@NicolasR 感谢其他问题的帮助。我能够通过对函数进行一些更改来使其工作。我也意识到可能是我打了太多的电话,但现在我终于明白了如何有效地使用每个功能。
标签: c# visual-studio exception microsoft-cognitive face-api