コード例 #1
0
 private async Task AddElementToDB(FERItem item, bool labeled = false)
 {
     if (labeled)
     {
         await AddElementToLabeledContainer(item);
     }
     else
     {
         await AddElementToUnlabeledContainer(item);
     }
 }
コード例 #2
0
        public async Task AddElementToLabeledContainer(FERItem item)
        {
            try
            {
                ItemResponse <FERItem> readItemIfNotExisting = await this.labeledContainer.ReadItemAsync <FERItem>(item.Id, new PartitionKey(item.Id));

                Console.WriteLine("Item in database with id: {0} already exists\n", readItemIfNotExisting.Resource.Id);
            }
            catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                ItemResponse <FERItem> createNewItem = await this.labeledContainer.CreateItemAsync <FERItem>(item, new PartitionKey(item.Id));

                // Note that after creating the item, we can access the body of the item with the Resource property off the ItemResponse. We can also access the RequestCharge property to see the amount of RUs consumed on this request.
                Console.WriteLine("Created item in database with id: {0} Operation consumed {1} RUs.\n", createNewItem.Resource.Id, createNewItem.RequestCharge);
            }
        }
コード例 #3
0
        internal async Task PostFERItem(FERItem ferItem)
        {
            try
            {
                // Detect - get features from faces.
                using MemoryStream ms = new MemoryStream(ferItem.Image);
                IList <DetectedFace> res = await client.Face.DetectWithStreamAsync(ms, false, false, new List <FaceAttributeType?> {
                    FaceAttributeType.Emotion
                });

                var faceemotions = res[0].FaceAttributes.Emotion;
                switch ((Emotion)ferItem.EmotionID)
                {
                case Emotion.Anger:
                    bool correct = CheckValueOfEmotion(faceemotions.Anger);
                    await AddElementToDB(ferItem, correct);

                    break;

                case Emotion.Happiness:
                    correct = CheckValueOfEmotion(faceemotions.Happiness);
                    await AddElementToDB(ferItem, correct);

                    break;

                case Emotion.Sadness:
                    correct = CheckValueOfEmotion(faceemotions.Sadness);
                    await AddElementToDB(ferItem, correct);

                    break;

                case Emotion.Fear:
                    correct = CheckValueOfEmotion(faceemotions.Fear);
                    await AddElementToDB(ferItem, correct);

                    break;

                case Emotion.Disgust:
                    correct = CheckValueOfEmotion(faceemotions.Disgust);
                    await AddElementToDB(ferItem, correct);

                    break;

                case Emotion.Surprise:
                    correct = CheckValueOfEmotion(faceemotions.Surprise);
                    await AddElementToDB(ferItem, correct);

                    break;

                case Emotion.Neutral:
                    correct = CheckValueOfEmotion(faceemotions.Neutral);
                    await AddElementToDB(ferItem, correct);

                    break;

                default:
                    await AddElementToUnlabeledContainer(ferItem);

                    break;
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
        }