Microsoft ProjectOxford Face API Error: System.UriFormatException
Microsoft ProjectOxford Face API Error: System.UriFormatException
我正在关注 this documentation 使用 Microsoft Face API 来识别 Visual Studio 中图像中的人脸,但在控制台中打印了以下错误:
Error adding Person to Group Exception of type 'Microsoft.ProjectOxford.Face.FaceAPIException' was thrown.
调用以下函数将人员添加到现有人员组时打印异常:
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 中搜索此错误并遇到了 ,但该答案对我不起作用。 (他们的回答是为 FaceServiceClient
构造函数传入订阅密钥和端点。)
任何人都可以深入了解为什么会出现此错误吗?我一直无法弄清楚是什么原因造成的,但我相信它可能必须这样做和
await faceServiceClient.GetPersonGroupAsync(personGroupId);
。我还读到这可能是由于我选择的认知服务定价计划。但是,我使用的免费交易允许每分钟 20 次交易,我只是想为 3 个不同的人添加 9 张图片。
我找到了解决问题的方法,方法是使用下面的新函数创建人员组,向其中添加人员,然后输入图像:
public async void AddPersonToGroup(string personGroupId, string name, string pathImage){
//Create a Person Group called actors.
await faceServiceClient.CreatePersonGroupAsync("actors, "Famous Actors");
//Create a person and assign them to a Person Group called "actors"
CreatePersonResult friend1 = await faceServiceClient.CreatePersonAsync("actors", "Tom Cruise");
//Get the directory with all the images of the person.
const string friend1ImageDir = @"C:\Users\ishaa\Documents\Face_Recognition_Pictures\Tom_Cruise\";
foreach (string imagePath in Directory.GetFiles(friend1ImageDir, "*.jpg")){
using (Stream s = File.OpenRead(imagePath)){
try{
//Add the faces for the person.
await faceServiceClient.AddPersonFaceAsync("actors", friend1.PersonId, s);
} catch (Exception e){
Console.WriteLine(e.Message);
}
}
}
}
上面的以下代码在创建人员组、创建人员以及为人员添加图像方面对我有用。我认为,最初的错误可能有两个原因:
await faceServiceClient.GetPersonGroupAsync(personGroupId);
可能是个问题。现在我不使用它了,代码适用于 faceServiceClient.CreatePersonGroupAsync
.
- 每分钟调用太多。我目前正在使用每分钟 20 t运行 次操作的免费计划。我没有意识到的是,每次我 运行 代码时,我都会用 API 进行多次调用,因为我正在调用用于创建人员组、添加人员、为人员添加图像的函数,训练 Person Group,然后识别一个 Person。我认为这是主要错误。
我正在关注 this documentation 使用 Microsoft Face API 来识别 Visual Studio 中图像中的人脸,但在控制台中打印了以下错误:
Error adding Person to Group Exception of type 'Microsoft.ProjectOxford.Face.FaceAPIException' was thrown.
调用以下函数将人员添加到现有人员组时打印异常:
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 中搜索此错误并遇到了 FaceServiceClient
构造函数传入订阅密钥和端点。)
任何人都可以深入了解为什么会出现此错误吗?我一直无法弄清楚是什么原因造成的,但我相信它可能必须这样做和
await faceServiceClient.GetPersonGroupAsync(personGroupId);
。我还读到这可能是由于我选择的认知服务定价计划。但是,我使用的免费交易允许每分钟 20 次交易,我只是想为 3 个不同的人添加 9 张图片。
我找到了解决问题的方法,方法是使用下面的新函数创建人员组,向其中添加人员,然后输入图像:
public async void AddPersonToGroup(string personGroupId, string name, string pathImage){
//Create a Person Group called actors.
await faceServiceClient.CreatePersonGroupAsync("actors, "Famous Actors");
//Create a person and assign them to a Person Group called "actors"
CreatePersonResult friend1 = await faceServiceClient.CreatePersonAsync("actors", "Tom Cruise");
//Get the directory with all the images of the person.
const string friend1ImageDir = @"C:\Users\ishaa\Documents\Face_Recognition_Pictures\Tom_Cruise\";
foreach (string imagePath in Directory.GetFiles(friend1ImageDir, "*.jpg")){
using (Stream s = File.OpenRead(imagePath)){
try{
//Add the faces for the person.
await faceServiceClient.AddPersonFaceAsync("actors", friend1.PersonId, s);
} catch (Exception e){
Console.WriteLine(e.Message);
}
}
}
}
上面的以下代码在创建人员组、创建人员以及为人员添加图像方面对我有用。我认为,最初的错误可能有两个原因:
await faceServiceClient.GetPersonGroupAsync(personGroupId);
可能是个问题。现在我不使用它了,代码适用于faceServiceClient.CreatePersonGroupAsync
.- 每分钟调用太多。我目前正在使用每分钟 20 t运行 次操作的免费计划。我没有意识到的是,每次我 运行 代码时,我都会用 API 进行多次调用,因为我正在调用用于创建人员组、添加人员、为人员添加图像的函数,训练 Person Group,然后识别一个 Person。我认为这是主要错误。