コード例 #1
0
        public string GetUrlPhotoWithEmotion(EmotionsType type)
        {
            string url             = string.Empty;
            double maxEmotionScore = 0;

            for (int i = 0; i < _EmotionsInformation.Count; i++)
            {
                EmoInfo emotInf             = _EmotionsInformation[i];
                double  currentEmotionScore = 0;
                int     facesCount          = emotInf.Emotions.Count;
                //если человек на фотографии не один - продолжаем дальше
                if (facesCount > 1)
                {
                    continue;
                }
                for (int j = 0; j < emotInf.Emotions.Count; j++)
                {
                    currentEmotionScore += EmoUtils.GetEmoScore(emotInf.Emotions[j], type);
                }
                if (currentEmotionScore > maxEmotionScore)
                {
                    maxEmotionScore = currentEmotionScore;
                    url             = emotInf.ImageUrl;
                }
            }
            return(url);
        }
コード例 #2
0
        private static async Task <List <EmoInfo> > GetDataFromMsCognitive(
            string userName,
            List <InstaInfo> instaInfo,
            string apiKey,
            bool isApiKeyTrial)
        {
            EmotionServiceClient _EmoClient  = new EmotionServiceClient(apiKey);
            List <EmoInfo>       emoInfoList = new List <EmoInfo>();

            Emotion[] emoInfo;
            for (int i = 0; i < instaInfo.Count; i++)
            {
                try
                {
                    if (isApiKeyTrial)
                    {
                        await Task.Delay(3000);
                    }
                    emoInfo = await _EmoClient.RecognizeAsync(instaInfo[i].PostImageUrl);

                    EmoInfo info = new EmoInfo();
                    info.ProfileFullName = instaInfo[i].ProfileName;
                    info.ImageUrl        = instaInfo[i].PostImageUrl;
                    info.CommentsCount   = instaInfo[i].CommentsCount;
                    info.LikesCount      = instaInfo[i].LikesCount;
                    info.Emotions        = emoInfo.ToList();
                    emoInfoList.Add(info);

                    System.Diagnostics.Debug.Write($"Photo number: {i}\n");
                }
                catch
                {
                }
            }
            System.Diagnostics.Debug.Write("Success!\n");
            return(emoInfoList);
        }