如何同时使用FaceRecognition和Emotion服务。 [英] How to use FaceRecognition and Emotion services at the same time.

查看:60
本文介绍了如何同时使用FaceRecognition和Emotion服务。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我使用FaceRecognition服务登录我的用户,之后我想知道他们是否满意。

I´m using FaceRecognition services to login my users, and after i want to know if they are happy.

如果我一个接一个地调用服务,一切都没问题,但是当我同时打电话时,第二个服务没有响应并发送和系统网络的例外.webexception:aborted。

If I call the services one by one all is ok, but when I call at the same time, the second services doesn´t response and send and exception of system.net.webexception: aborted.

我尝试在调用另一个之前处置FaceRecognition服务。 

I try to dispose the FaceRecognition services before call the other. 

我在两个异步任务中调用它们。

I call them in two async Tasks.

 public async Task FindUser(Stream stream)
        {
            var faceServiceClient = new FaceServiceClient("**************************");


            Face[] faces = null;
            try
            {
                // Step 4a - Detect the faces in this photo.
                faces = await faceServiceClient.DetectAsync(stream, true, true, requiredFaceAttributes);
            }
            catch (Exception ex)
            {
              return;
            }
            if (faces.ToList().Count > 0)
            {

                var faceIds = faces.Select(faceOne => face.FaceId).ToArray();

                // Step 4b - Identify the person in the photo, based on the face.
                var results = await faceServiceClient.IdentifyAsync("1", faceIds);
                var result = results[0].Candidates[0].PersonId;

                // Step 4c - Fetch the person from the PersonId and display their name.
                var person = await faceServiceClient.GetPersonAsync("1", result);
                if (person != null)
                {

                     await GetEmotions(stream);

                 }

}


private async Task<Emotion> GetEmotions(Stream stream)
        {
            var emotionServiceClient = new EmotionServiceClient("****************************");

            var emotions = await emotionServiceClient.RecognizeAsync(stream);
            if (emotions == null || !emotions.Any())
            {
                return null;
            }
            return emotions[0];
        }

推荐答案

当您调用faceServiceClient.DetectAsync(stream,...)时,您将从该流中读取。  ;为了再次从该流中读取(就像调用emotionServiceClient.RecognizeAsync(stream)一样),您需要重置该流。 如果
流支持搜索,则可以调用stream.Position = 0,或者如果您的流不支持它,则可能需要stream.Clone()。
When you call faceServiceClient.DetectAsync(stream,...), you will read from that stream.  In order to read from that stream again (as you would, to call emotionServiceClient.RecognizeAsync(stream)), you will need to reset that stream.  If you stream supports seeking, you can call stream.Position = 0, or if your stream does not support it, you may need to stream.Clone().


这篇关于如何同时使用FaceRecognition和Emotion服务。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆