因为等待和异步函数,我在做这件事时遇到了困难。我想要一个实时分析脸的应用程序,它可以分解他脸上的长方形,上面写着性别、年龄、情感、情感和情感舞蹈。所以我想同时使用Face API和情感API。谢谢。
发布于 2017-03-09 03:25:12
复制与Calling the face and emotion API at the same time。
有关更多信息,请参考该帖子。
发布于 2017-03-07 04:23:39
假设您使用的是C# SDK,您可以等待这两个任务完成。代码需要这样的内容:
static bool SameFace(Microsoft.ProjectOxford.Face.Contract.FaceRectangle r1,
Microsoft.ProjectOxford.Common.Rectangle r2)
{
// Fuzzy match of rectangles...
return Math.Abs((r1.Top + r1.Height / 2) - (r2.Top + r2.Height / 2)) < 3 &&
Math.Abs((r1.Left + r1.Width / 2) - (r2.Left + r2.Width / 2)) < 3;
}
void Test(string imageUrl)
{
var faceClient = new FaceServiceClient(FACE_API_KEY);
var emotionClient = new EmotionServiceClient(EMOTION_API_KEY);
var faceTask = faceClient.DetectAsync(imageUrl, false, false, new FaceAttributeType[] { FaceAttributeType.Age, FaceAttributeType.Gender });
var emotionTask = emotionClient.RecognizeAsync(imageUrl);
Task.WaitAll(faceTask, emotionTask);
var people = from face in faceTask.Result
from emotion in emotionTask.Result
where SameFace(face.FaceRectangle, emotion.FaceRectangle)
select new {
face.FaceAttributes.Gender,
face.FaceAttributes.Age,
emotion.Scores
};
// Do something with 'people'
}
棘手的部分是这两个API不具有相同的矩形类型,并且给出了稍微不同的值,因此是模糊匹配。
https://stackoverflow.com/questions/42597455
复制相似问题