I wanted to create a simple program to detect faces using Microsoft Azure Face API and Visual Studio 2015. Following the guide from (https://social.technet.microsoft.com/wiki/contents/articles/37893.c-face-detection-and-recognition-with-azure-face-api.aspx), whenever my program calls UploadAndDetectFaces:
private async Task<Face[]> UploadAndDetectFaces(string imageFilePath)
{
try
{
using (Stream imageFileStream = File.OpenRead(imageFilePath))
{
var faces = await faceServiceClient.DetectAsync(imageFileStream,
true,
true,
new FaceAttributeType[]
{
FaceAttributeType.Gender,
FaceAttributeType.Age,
FaceAttributeType.Emotion
});
return faces.ToArray();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return new Face[0];
}
}
I also declared the keys to the endpoint:
private readonly IFaceServiceClient faceServiceClient = new FaceServiceClient("MY_KEY_HERE");
an error returns:
"Exception of type 'Microsoft.ProjectOxford.Face.FaceAPIException' was thrown."
Does anyone know what's wrong or any changes required to prevent the error?
Change the key and endpoint declaration to:
private readonly IFaceServiceClient faceServiceClient = new FaceServiceClient("MY_KEY_HERE", "ACTUAL_ENDPOINT_HERE");
来源:https://stackoverflow.com/questions/47885650/face-api-detectasync-error