コード例 #1
0
        public void GetEmotionInputTest()
        {
            var imagePath = @"E:\Senparc\AzureDemo\WebSite\Senparc.Web\Upload\Emotion\img.jpg";
            var dt1       = DateTime.Now;

            Console.WriteLine("Begin DateTime:{0}".With(dt1));

            for (var i = 0; i < 10; i++)
            {
                //Thread thread = new Thread(() =>
                //{
                var dt2 = DateTime.Now;
                Console.WriteLine("Async DateTime:{0}".With(dt2));
                var emotion = EmotionApi.UploadAndStreamDetectEmotionsAsync(imagePath);
                Console.WriteLine("=========={0}".With(emotion.Result.ToJson()));
                Console.WriteLine("End Async DateTime:{0}".With((DateTime.Now - dt1).TotalMilliseconds));
                //});
                //thread.Start();
                //var module = new EmotionApiModule();
                //var result = _workFlowModuleService.GetEmotionInput(emotion[0]);
                //Assert.IsNotNull(result);
                //foreach (var parameter in result)
                //{
                //    Console.WriteLine("=========={0}:{1}".With(parameter.Name, parameter.Value));
                //}
            }
            Console.WriteLine("End DateTime:{0}".With((DateTime.Now - dt1).TotalMilliseconds));
        }
コード例 #2
0
        public HowAreYouDialog(SentimentAnalysisService sentimentAnalysisService, EmotionApi emotionApi)
            : base("HowAreYou")
        {
            Check.Required <ArgumentNullException>(() => sentimentAnalysisService != null);
            Check.Required <ArgumentNullException>(() => emotionApi != null);

            _sentimentAnalysisService = sentimentAnalysisService;
            _emotionApi = emotionApi;
        }
コード例 #3
0
        /// <summary>
        /// Uploads the image stored from the properties here and returns a representation
        /// of the object data.
        /// </summary>
        /// <returns></returns>
        public async Task UploadAndAnalyzeImageAsync()
        {
            try
            {
                IsProgressBarEnabled = true;

                //receive the JSON string if successful.
                string rawData = await EmotionApi.PostImageAsync(SelectedImage, ImageBytes);

                // From the derived raw string of JSON from the server, it will be
                // deserialized to the model. See Model/EmotionData.cs for the definition files.
                //
                // Before implementing this, you have to go to:
                // Tools->Package Manager->Package Manager Console
                // then type (without quotes) "Install-Package Newtonsoft.Json".
                // Ctrl + period when necessary.
                List <EmotionData> people = JsonConvert.DeserializeObject <List <EmotionData> >(rawData);

                // Now let's translate the data from the server to the RectGeometry property
                // of each EmotionData, which represents the list of heads and their emotions,
                // based on the API.
                foreach (var emotion in people)
                {
                    // create a geometry
                    RectangleGeometry geom = new RectangleGeometry();
                    geom.Rect = new Windows.Foundation.Rect(emotion.FaceRectangle.Left, emotion.FaceRectangle.Top, emotion.FaceRectangle.Width, emotion.FaceRectangle.Height);

                    // attach the geometry to the property
                    emotion.RectGeometry = geom;
                }

                IsProgressBarEnabled = false;

                // The emotion data is now being assigned to the observable collection
                // where the overlay of rectangles will be bound to.
                DetectedFaces = new ObservableCollection <EmotionData>(people);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
        /// <summary>
        /// 获取Api返回的Input[根据下面所有的工作项需要返回]
        /// </summary>
        /// <param name="fullAccountWorkFlow"></param>
        /// <param name="picValue"></param>
        /// <param name="currentModule"></param>
        /// <returns></returns>
        private async Task <Input> GetMoodsApiModuleInputAsync(FullAccountWorkFlow fullAccountWorkFlow, string picValue,
                                                               BaseModule currentModule)
        {
            if (picValue == null || fullAccountWorkFlow.Input.All(z => z.Name != picValue))
            {
                throw new Exception("输入参数节点有误认知服务{0}!".With(currentModule.Step));
            }
            var inputPic     = fullAccountWorkFlow.Input.FirstOrDefault(z => z.Name == picValue);
            var picUrl       = Convert.ToString(inputPic.Value);
            var absoluteUrl  = Server.GetMapPath(picUrl.StartsWith("~/") ? picUrl : "~" + picUrl);
            var emotionArray = await EmotionApi.UploadAndStreamDetectEmotionsAsync(absoluteUrl); //TODO:调用Azure情绪识别API

            if (emotionArray == null || emotionArray.Length <= 0)
            {
                Log.LogUtility.DebugLogger.Info("图片路径:{0}!".With(absoluteUrl));
                throw new Exception("您上传的图片没有监测到面部表情!");
            }
            var currentInput = GetEmotionInput(emotionArray[0]);

            return(currentInput);
        }
コード例 #5
0
        public void UploadAndStreamDetectEmotionsTest()
        {
            var imageFilePath = @"E:\Senparc\AzureDemo\WebSite\Senparc.Web\Upload\Emotion\happy.jpg";

            Console.WriteLine("Begin Time: {0}", DateTime.Now);
            var result = EmotionApi.UploadAndStreamDetectEmotions(imageFilePath);

            Console.WriteLine("End Time: {0}", DateTime.Now);
            Assert.IsNotNull(result);
            foreach (var item in result)
            {
                Console.WriteLine(
                    "FaceRectangle=======Height:{0}====Width:{1}====Left:{2}====Top:{3}".With(
                        item.FaceRectangle.Height, item.FaceRectangle.Width,
                        item.FaceRectangle.Left, item.FaceRectangle.Top));
                foreach (var keyValuePair in item.Scores.ToRankedList())
                {
                    Console.WriteLine("Scores===={0}:{1}".With(keyValuePair.Key, keyValuePair.Value));
                }
                Console.WriteLine("=============================");
            }
        }