private void CreateTestData(FaceData faceData, int idx) { AuTestData = new svm_node[MaxAuFeatures]; FppTestData = new svm_node[MaxFppFeatures]; for (int i = 0; i < faceData.au_data.Count; i++) { AuTestData[i] = new svm_node(); AuTestData[i].index = i; AuTestData[i].value = faceData.au_data[i]; } int index = 0; int j = 0; while (index < faceData.point_3D.Count) { if (FeaturePoint.ContainsValue(index / 3)) { FppTestData[j] = new svm_node(); FppTestData[j].index = j; FppTestData[j].value = faceData.point_3D[index]; j++; } index++; } ScalingData(AuTestData, AuScaleMin, AuScaleMax, MaxAuFeatures, idx); ScalingData(FppTestData, FppScaleMin, FppScaleMax, MaxFppFeatures, idx); }
private void TestSVM(FaceData newData) { for (int i = 0; i < 7; i++) { //Create test data CreateTestData(newData, i); //Get the result of estimation AuClassLabel[i] = (int)svm.svm_predict(AuModel[i], AuTestData); FppClassLabel[i] = (int)svm.svm_predict(FppModel[i], FppTestData); } }
public void showFace3D(FaceData newData) { txtPitch.Content = Math.Round(newData.head3D[0], 0) + "°"; txtYaw.Content = Math.Round(newData.head3D[1], 0) + "°"; txtRoll.Content = Math.Round(newData.head3D[2], 0) + "°"; }
public void process(FaceData newData) { try { int time_change = (int)mainForm.thisTime.Subtract(fps_lastCheck).TotalSeconds; if (time_change >= 1) { txtFps.Content = "fps " + fps_counter; fps_lastCheck = mainForm.thisTime; fps_counter = 0; } fps_counter++; //===================================================== if (checkRun.IsChecked.Value) { //------ Test (Show Data) 以下に自分のコード記述-------------- //initialize class labels of each data InitializeSVM(); //do classfication using SVM TestSVM(newData); for (int i = 0; i < 7; i++) { //Remove first element if dictionary size is more than equal 30. if (AuDictionary[i].Count >= MaxRecordFrame) { AuDictionary[i].RemoveAt(0); } if (FppDictionary[i].Count >= MaxRecordFrame) { FppDictionary[i].RemoveAt(0); } //Add the result of classfication AuDictionary[i].Add(AuClassLabel[i]); FppDictionary[i].Add(FppClassLabel[i]); } //Sum labels for (int i = 0; i < 7; i++) { AuC[i] = AuDictionary[i].Sum(); FppC[i] = FppDictionary[i].Sum(); } //Get index which sum of labels is the highest int[] AuMaxEmotionIndex = AuC.Select((item, index) => new { Index = index, Value = item }) .Where(item => item.Value == AuC.Max()) .Select(item => item.Index).ToArray(); int[] FppMaxEmotionIndex = FppC.Select((item, index) => new { Index = index, Value = item }) .Where(item => item.Value == FppC.Max()) .Select(item => item.Index).ToArray(); Random rnd = new Random(); AuMaxEmotionIndex[0] = AuMaxEmotionIndex[rnd.Next(AuMaxEmotionIndex.Count())]; FppMaxEmotionIndex[0] = FppMaxEmotionIndex[rnd.Next(FppMaxEmotionIndex.Count())]; FinalEstimation = (AuC.Max() > FppC.Max()) ? AuMaxEmotionIndex[0] : FppMaxEmotionIndex[0]; //output on Window currentEmotion = FinalEstimation; txtOutput.Content = "" + EmotionIndex[FinalEstimation]; showFace3D(newData); } } catch (Exception ex) { TheSys.showError(ex); } }