private async void Button_OpenFile(object sender, RoutedEventArgs e) { var picker = new Windows.Storage.Pickers.FileOpenPicker { ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail, SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary }; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); StorageFile photo = await picker.PickSingleFileAsync(); if (photo != null) { var api = new AzureFaceApi(); var emotion = await api.UploadFaceAndGetEmotions(photo); if (emotion != null) { EmotionModel = new EmotionModel(emotion, photo.Path); } } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Score,FaceId,Type")] EmotionModel emotionModel) { if (id != emotionModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(emotionModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmotionModelExists(emotionModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FaceId"] = new SelectList(_context.Faces, "Id", "Id", emotionModel.FaceId); return(View(emotionModel)); }
//Add to our current model! void OnMouseDown() { Vector3 vectorToAdd = gameObject.transform.position.normalized; vectorToAdd *= (_drawEmotionModel.CircleScale + _drawEmotionModel.IdealOffset); EmotionModel.ChangeStateByAddingVector(vectorToAdd); }
/// <summary> /// Given a word, we want to add the word and the synonyms to the dictionary (given /// that it's a valid word) and save it. Then we want to pass the word off /// to the controller that will convert it into a list of EmotionIdeals. /// </summary> /// <param name="word">The word with its synonyms. Note this word could be garbage!</param> /// <returns></returns> private static Word CallMeWhenDonePingingServer(Word word) { Debug.Log("New synonym done pinging server for word: " + word.GetWord()); string wordStr = word.GetWord(); if (word.IsGarbage()) { Debug.Log("word '" + word.GetWord() + "' thrown away, since it's garbage"); return(word); } //TO-DO: Now that we have the filled word, we need to get the EmotionIdeal it represents! List <EmotionModel.EmotionIdeal> emoIdealList = new List <EmotionModel.EmotionIdeal>(); EmotionModel.EmotionIdeal emotionIdeal = Emotions.GetEmotionIdealAssociated(word.GetWord()); if (emotionIdeal != EmotionModel.EmotionIdeal.None) { emoIdealList.Add(emotionIdeal); } foreach (string synonym in word.GetSynonyms()) { emotionIdeal = Emotions.GetEmotionIdealAssociated(synonym); if (emotionIdeal != EmotionModel.EmotionIdeal.None) { emoIdealList.Add(emotionIdeal); } } if (emoIdealList.Count > 0) { //pick a random emotion ideal in the list int randIndex = Random.Range(0, emoIdealList.Count - 1); emotionIdeal = emoIdealList[randIndex]; //And then have it affect the emotional model MySQLDictionary.AddEntry(wordStr, emotionIdeal); EmotionModel.ChangeStateByAddingEmotions(emotionIdeal); } else { Debug.Log("Word: " + word.GetWord() + " : has no associated emotion ideal"); } ////add the new word to the dictionary //SynonymDictionary.Add(word.GetWord(), word.GetSynonyms()); // ////If we should save, do it //if (Time.time - SynonymDictionary.LastSave > SynonymDictionary.MIN_TIME_BETWEEN_SAVES) //{ // SynonymDictionary.SaveSynonymDictionary(); //} return(word); }
private string GetEmo(EmotionModel item) { List <double> list = new List <double>(); Scores scores = item.scores; list.Add(scores.happiness); list.Add(scores.anger); list.Add(scores.sadness); list.Add(scores.neutral); list.Add(scores.contempt); list.Add(scores.disgust); list.Add(scores.fear); list.Add(scores.surprise); var listSorted = list.OrderBy(i => i).ToList(); double maxElementList = listSorted[listSorted.Count - 1]; if (maxElementList == scores.anger) { return("Anger"); } else if (maxElementList == scores.happiness) { return("Happy"); } else if (maxElementList == scores.sadness) { return("Sadness"); } else if (maxElementList == scores.neutral) { return("Neutral"); } else if (maxElementList == scores.contempt) { return("Contempt"); } else if (maxElementList == scores.disgust) { return("Disgust"); } else if (maxElementList == scores.fear) { return("Fear"); } else if (maxElementList == scores.surprise) { return("Surprise"); } else { return("Neutral"); } }
public async Task <IActionResult> Create([Bind("Id,Score,FaceId,Type")] EmotionModel emotionModel) { if (ModelState.IsValid) { _context.Add(emotionModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FaceId"] = new SelectList(_context.Faces, "Id", "Id", emotionModel.FaceId); return(View(emotionModel)); }
private void Btn_MouseClick(object sender, DuiMouseEventArgs e) { var btn = sender as DuiButton; if (btn != null) { EmotionModel model = btn.Tag as EmotionModel; if (model != null) { click(model); } } }
/// <summary> /// max value of emotion /// </summary> /// <param name="item"></param> /// <returns></returns> public static string GetEmo(EmotionModel item) { List <double> list = new List <double>(); EScores sc = item.scores; list.Add(sc.anger); list.Add(sc.happiness); list.Add(sc.contempt); list.Add(sc.neutral); list.Add(sc.disgust); list.Add(sc.sadness); list.Add(sc.surprise); list.Add(sc.fear); var listSorted = list.OrderBy(i => i).ToList(); double maxElementInList = listSorted[listSorted.Count - 1]; if (maxElementInList == sc.anger) { return("화가 나있습니다."); } else if (maxElementInList == sc.happiness) { return("행복해 합니다."); } else if (maxElementInList == sc.contempt) { return("경멸스러워 합니다."); } else if (maxElementInList == sc.sadness) { return("슬퍼하고 있습니다."); } else if (maxElementInList == sc.fear) { return("무서워하고 있습니다."); } else if (maxElementInList == sc.surprise) { return("놀랐습니다."); } else if (maxElementInList == sc.disgust) { return("역겨워 미쳐합니다."); } else { return("아무런 반응 없이 있습니다."); } }
private IEnumerator ProcessCo(string word) { //First throw the word out if it's too long! if (word.Length > MySQLDictionary.MAX_WORD_LENGTH) { yield break; } word = Utility.SanitizeString(word); ////Now determine if we already have the word! //List<string> synonyms; //if (SynonymDictionary.TryGetValue(word, out synonyms)) //if we find it in the dictionary //{ // Word wordWithSynonyms = new Word(word, synonyms); // // //TO-DO: Now that we have the synonyms, send it to a controller that converts the strings into a list of EmotionIdeals // CallMeToPassOnWord(wordWithSynonyms); //} MySQLDictionary.WVObject <bool?> dbHasWord = MySQLDictionary.DatabaseContainsEntry(word); while (!dbHasWord.IsDone) { yield return(null); } if ((bool)dbHasWord.value) { MySQLDictionary.WVObject <MySQLDictionary.WordAndEmoIdeal> result = MySQLDictionary.GetWordFromDatabase(word); while (!result.IsDone) { yield return(null); } //Now that we have the word and emotion ideal, we can pass add it to our model EmotionModel.ChangeStateByAddingEmotions(result.value.emoEnum); } else //else we need to ping the server! { //SynonymFinder.OnSynonymCompleteDelegate synDelegate = Instance.CallMeWhenDonePingingServer(); /* This will create a get request for a new Word that will be populated with the word's * synonyms. The callback is what's called once it's finished getting the synonyms. * In this case, after getting the synonyms we want to * - Add the new word/synonynms to the dictionary * - Do something with the new Word object, to convert it into EmotionIdeals */ System.Func <Word, Word> callback = CallMeWhenDonePingingServer; Synonym newWord = new Synonym(word, callback); } }
/// <summary> /// Result of Emotion /// </summary> /// <param name="params"></param> /// <returns></returns> protected override string RunInBackground(params Stream[] @params) { try { PublishProgress("감정 분석 중입니다..."); emotionRestClient = new EmotionServiceRestClient(EmotionKey); var result = emotionRestClient.RecognizeImage(@params[0]); var list = new List <EmotionModel>(); if (result != null) { foreach (var item in result) { EmotionModel eM = new EmotionModel(); //감정분석 API Com.Microsoft.Projectoxford.Emotion.Contract.FaceRectangle faceRect = item.FaceRectangle; eM.faceRectangle = new EFaceRectangle(); eM.faceRectangle.left = faceRect.Left; eM.faceRectangle.top = faceRect.Top; eM.faceRectangle.width = faceRect.Width; eM.faceRectangle.height = faceRect.Height; Com.Microsoft.Projectoxford.Emotion.Contract.Scores sc = item.Scores; eM.scores = new EScores(); eM.scores.anger = sc.Anger; eM.scores.happiness = sc.Happiness; eM.scores.contempt = sc.Contempt; eM.scores.fear = sc.Fear; eM.scores.surprise = sc.Surprise; eM.scores.neutral = sc.Neutral; eM.scores.sadness = sc.Sadness; eM.scores.disgust = sc.Disgust; list.Add(eM); } return(JsonConvert.SerializeObject(list)); } return(null); } catch (System.Exception ex) { return(null); } }
/// <summary> /// Emotion Result Function /// </summary> /// <param name="result"></param> /// <returns></returns> public static string EmotionResult(IList <RecognizeResult> result) { List <EmotionModel> EMI = new List <EmotionModel>(); foreach (var item in result) { EmotionModel eM = new EmotionModel(); Com.Microsoft.Projectoxford.Emotion.Contract.FaceRectangle faceRect = item.FaceRectangle; eM.faceRectangle = new EFaceRectangle(); eM.faceRectangle.left = faceRect.Left; eM.faceRectangle.top = faceRect.Top; eM.faceRectangle.width = faceRect.Width; eM.faceRectangle.height = faceRect.Height; Scores sc = item.Scores; eM.scores = new EScores(); eM.scores.anger = sc.Anger; eM.scores.happiness = sc.Happiness; eM.scores.contempt = sc.Contempt; eM.scores.fear = sc.Fear; eM.scores.surprise = sc.Surprise; eM.scores.neutral = sc.Neutral; eM.scores.sadness = sc.Sadness; eM.scores.disgust = sc.Disgust; EMI.Add(eM); } EmotionModel EMax = new EmotionModel(); EMax = EMI[0]; foreach (var face in EMI) { if (EMax.faceRectangle.height * EMax.faceRectangle.width <= face.faceRectangle.height * face.faceRectangle.width) { EMax = face; //제일 큰 얼굴값을 택함 } } return(GetEmo(EMax)); }
private async void Button_OpenCamera(object sender, RoutedEventArgs e) { var capture = new CameraCaptureUI(); capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; capture.PhotoSettings.CroppedSizeInPixels = new Size(200, 200); StorageFile photo = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo); if (photo != null) { var api = new AzureFaceApi(); Emotion emotion = await api.UploadFaceAndGetEmotions(photo); if (emotion != null) { var emo = new EmotionModel(emotion, photo.Path); EmotionModel = emo; CameraView.AddEmotionModelToView(EmotionModel); } } }
protected override string RunInBackground(params Stream[] @params) { try { PublishProgress("Recognizing..."); var result = secondActivity.emotionRestClient.RecognizeImage(@params[0]); var list = new List <EmotionModel>(); foreach (var item in result) { EmotionModel emotionModel = new EmotionModel(); Com.Microsoft.Projectoxford.Emotion.Contract.FaceRectangle faceRect = item.FaceRectangle; emotionModel.faceRectangle = new FaceRectangle(); emotionModel.faceRectangle.left = faceRect.Left; emotionModel.faceRectangle.top = faceRect.Top; emotionModel.faceRectangle.width = faceRect.Width; emotionModel.faceRectangle.height = faceRect.Height; Com.Microsoft.Projectoxford.Emotion.Contract.Scores scores = item.Scores; emotionModel.scores = new Scores(); emotionModel.scores.anger = scores.Anger; emotionModel.scores.happiness = scores.Happiness; emotionModel.scores.sadness = scores.Sadness; emotionModel.scores.fear = scores.Fear; emotionModel.scores.neutral = scores.Neutral; emotionModel.scores.surprise = scores.Surprise; emotionModel.scores.disgust = scores.Disgust; list.Add(emotionModel); } string strResult = JsonConvert.SerializeObject(list); return(strResult); } catch (Exception ex) { System.Console.Write(ex); return(null); } }
/// <summary> /// Show the best of Emotion /// </summary> /// <param name="result"></param> protected override void OnPostExecute(string result) { if (result != null) { var list = JsonConvert.DeserializeObject <List <EmotionModel> >(result); EmotionModel EMax = new EmotionModel(); if (list.Count > 0) { EMax = list[0]; foreach (var face in list) { if (EMax.faceRectangle.height * EMax.faceRectangle.width <= face.faceRectangle.height * face.faceRectangle.width) { EMax = face; //제일 큰 얼굴값을 택함 } } string tmp = EmotionFunction.GetEmo(EMax); cognitiveActivity.textValue += tmp; cognitiveActivity.tvText.Text = cognitiveActivity.textValue; pd.Dismiss(); } } }
//Процентный расчет эмоционального состояния человека public async Task <EmotionModel> GetEmotionalReaction(int productId) { //получаем отклонения от начального значения var deviations = await GetDeviations(productId); var emotionModel = new EmotionModel(); // если пульс меньше нула берем промежутки в 10 единиц. При уменьшении на 10 счастье -5, расслабление +20 if (deviations.Pulse < 0) { if (deviations.Pulse >= -10) { emotionModel.Happy += 20; emotionModel.Relaxed += 10; } else if (deviations.Pulse >= -20) { emotionModel.Happy += 15; emotionModel.Relaxed += 30; } else if (deviations.Pulse >= -30) { emotionModel.Happy += 10; emotionModel.Relaxed += 50; } else if (deviations.Pulse >= -40) { emotionModel.Happy += 5; emotionModel.Relaxed += 60; } } // если пульс больше 0 берем промежутки по 10 единиц. При увеличении на 10 счастье -5, стресс +10 if (deviations.Pulse > 0) { if (deviations.Pulse >= 10) { emotionModel.Happy += 20; emotionModel.Strassed += 10; } else if (deviations.Pulse >= 20) { emotionModel.Happy += 15; emotionModel.Strassed += 20; } else if (deviations.Pulse >= 30) { emotionModel.Happy += 10; emotionModel.Strassed += 30; } else if (deviations.Pulse >= 40) { emotionModel.Happy += 5; emotionModel.Strassed += 40; } } // если температура больше 0, при увеличении на 1 , злость и стресс + 10 if (deviations.Temperature > 0) { if (deviations.Temperature <= 1) { emotionModel.Angry += 10; emotionModel.Strassed += 10; } else if (deviations.Temperature <= 2) { emotionModel.Angry += 20; emotionModel.Strassed += 20; } else if (deviations.Temperature <= 3) { emotionModel.Angry += 30; emotionModel.Strassed += 30; } else if (deviations.Temperature <= 4) { emotionModel.Angry += 40; emotionModel.Strassed += 40; } } // если тепература <0, каждый 1 градус понжения +10 к расслаблению if (deviations.Temperature < 0) { if (deviations.Temperature >= -1) { emotionModel.Relaxed += 10; } else if (deviations.Temperature >= -2) { emotionModel.Relaxed += 20; } else if (deviations.Temperature >= -3) { emotionModel.Relaxed += 30; } else if (deviations.Temperature >= -4) { emotionModel.Relaxed += 40; } } if (deviations.BloodPressure < 0) { if (deviations.BloodPressure >= -10) { emotionModel.Relaxed += 10; emotionModel.Happy += 30; } else if (deviations.BloodPressure >= -20) { emotionModel.Relaxed += 20; emotionModel.Happy += 25; } else if (deviations.BloodPressure >= -30) { emotionModel.Relaxed += 30; emotionModel.Happy += 20; } else if (deviations.BloodPressure >= -40) { emotionModel.Relaxed += 40; emotionModel.Happy += 15; } else if (deviations.BloodPressure >= -50) { emotionModel.Relaxed += 50; emotionModel.Happy += 10; } } if (deviations.BloodPressure > 0) { if (deviations.BloodPressure < 10) { emotionModel.Strassed += 15; emotionModel.Happy += 30; } else if (deviations.BloodPressure < 20) { emotionModel.Strassed += 30; emotionModel.Happy += 25; } else if (deviations.BloodPressure < 30) { emotionModel.Strassed += 45; emotionModel.Happy += 20; } else if (deviations.BloodPressure < 40) { emotionModel.Strassed += 60; emotionModel.Happy += 15; } else if (deviations.BloodPressure < 50) { emotionModel.Strassed += 70; emotionModel.Happy += 10; } } if (deviations.BloodOxygenLevel < 0) { if (deviations.BloodOxygenLevel >= -1) { emotionModel.Relaxed += 10; } else if (deviations.BloodOxygenLevel >= -2) { emotionModel.Relaxed += 20; } else if (deviations.BloodOxygenLevel >= -3) { emotionModel.Relaxed += 30; } else if (deviations.BloodOxygenLevel >= -4) { emotionModel.Relaxed += 40; } } if (deviations.BloodOxygenLevel > 0) { if (deviations.BloodOxygenLevel < 1) { emotionModel.Strassed += 15; emotionModel.Angry += 10; } else if (deviations.BloodOxygenLevel < 2) { emotionModel.Strassed += 30; emotionModel.Angry += 15; } else if (deviations.BloodOxygenLevel < 3) { emotionModel.Strassed += 45; emotionModel.Angry += 20; } else if (deviations.BloodOxygenLevel < 4) { emotionModel.Strassed += 60; emotionModel.Angry += 25; } else if (deviations.BloodOxygenLevel < 5) { emotionModel.Strassed += 70; emotionModel.Angry += 30; } } return(emotionModel); }