public void ReaddataByFrame(string path, int n) { if (path == null) { return; } int i = 1; StreamReader sr = new StreamReader(path, Encoding.Default); string line; while (((line = sr.ReadLine()) != null)) { if (i == n) { break; } i++; } string[] strArray = line.Split('\t'); SavaData(strArray); FeatureEuclidean firstfacedata = new FeatureEuclidean(_firstfacedata); FeatureEuclidean nowfacedata = new FeatureEuclidean(_nowfacedata); CatureFeature(nowfacedata, n); CatureFeature(firstfacedata, nowfacedata); Recongnize rec = new Recongnize();//识别类 rec.DeltaEulidean(firstfacedata, nowfacedata); _result = rec.GetResult; }
private void CatureFeature(FeatureEuclidean frameFeature, int n)//计算距离特征方法重载,第n帧 { float[] f1 = frameFeature.Feature; if (n == 1 && _delta[0, 1] == 0) { for (int i = 1; i < 26; i++) { _delta[0, i] = f1[i]; } } else if (n == _framesum && _delta[3, 1] == 0) { for (int i = 1; i < 26; i++) { _delta[3, i] = f1[i]; } } else { for (int i = 1; i < 26; i++) { _delta[1, i] = f1[i]; } } }
//private List<PointRecorder> _facedata = new List<PointRecorder>(); #region 构造方法 public Readdata(string path) { if (path == null) { return; } StreamReader sr = new StreamReader(path, Encoding.Default); string line; while ((line = sr.ReadLine()) != null) { _framesum++; string[] strArray = line.Split('\t'); SavaData(strArray); } ReaddataAllFrame(path, _framesum); FeatureEuclidean firstfacedata = new FeatureEuclidean(_firstfacedata); FeatureEuclidean nowfacedata = new FeatureEuclidean(_nowfacedata); CatureFeature(firstfacedata, 1); CatureFeature(nowfacedata, _framesum); }
private void CatureFeature(FeatureEuclidean firstFeature, FeatureEuclidean nowFeature)//差值 { float[] f1 = firstFeature.Feature; float[] f2 = nowFeature.Feature; for (int i = 1; i < 26; i++) { _delta[2, i] = f2[i] - f1[i]; } }
private void ReaddataAllFrame(string path, int n) { _resultList.Clear(); if (path == null) { return; } int i = 1, tag = 0; StreamReader sr = new StreamReader(path, Encoding.Default); string line; while (((line = sr.ReadLine()) != null)) { if (i == n) { break; } string[] strArray = line.Split('\t'); SavaData(strArray); FeatureEuclidean firstfacedata = new FeatureEuclidean(_firstfacedata); FeatureEuclidean nowfacedata = new FeatureEuclidean(_nowfacedata); CatureFeature(nowfacedata, n); CatureFeature(firstfacedata, nowfacedata); Recongnize rec = new Recongnize();//识别类 rec.DeltaEulidean(firstfacedata, nowfacedata); if (rec.GetResult != "Normal") { // tag = 1; //if(tag==1) _resultList.Add(rec.GetResult); } i++; } _result = ReturnAnsRate(_resultList); int di = 0; }
public void DeltaEulidean(FeatureEuclidean f1, FeatureEuclidean f2) { _result = EmotionLabel.Normal.ToString(); Dictionary <EmotionLabel, bool> emotion = new Dictionary <EmotionLabel, bool>(); emotion.Add(EmotionLabel.Anger, false); emotion.Add(EmotionLabel.Happiness, false); emotion.Add(EmotionLabel.Sadness, false); emotion.Add(EmotionLabel.Surprise, false); emotion.Add(EmotionLabel.Disgust, false); emotion.Add(EmotionLabel.Fear, false); //Suprise if (Math.Abs(f1.Feature[20] - f2.Feature[20]) > 18) //Suprise { emotion[EmotionLabel.Surprise] = true; _result = EmotionLabel.Surprise.ToString(); } //Happyness int[] a = { 15, 16, 22, 23 }; //Happyness int tag = 0; for (int i = 0; i < 4; i++) { if ((Math.Abs(f1.Feature[a[i]] - f2.Feature[a[i]]) > 10)) { tag++; } } if (_result != "Surprise" && tag >= 4) { _result = EmotionLabel.Happiness.ToString(); emotion[EmotionLabel.Happiness] = true; } //sadness if ((Math.Abs(f1.Feature[3] - f2.Feature[3]) > 2)) //sadness { if ((Math.Abs(f1.Feature[22] - f2.Feature[22]) > 8)) { if ((Math.Abs(f1.Feature[23] - f2.Feature[23]) > 8)) { _result = EmotionLabel.Sadness.ToString(); emotion[EmotionLabel.Sadness] = true; } } } //angry if ((Math.Abs(f1.Feature[19] - f2.Feature[19]) > 8)) //angry // if ((Math.Abs(f1.Feature[21] - f2.Feature[21]) > 5)) { if ((Math.Abs(f1.Feature[15] - f2.Feature[15]) > 10)) { if ((Math.Abs(f1.Feature[16] - f2.Feature[16]) > 10)) { if ((Math.Abs(f1.Feature[3] - f2.Feature[3]) > 4)) { _result = EmotionLabel.Anger.ToString(); emotion[EmotionLabel.Anger] = true; } } } } float tag_11_12 = f1.Feature[11] - f2.Feature[11] + f1.Feature[12] - f2.Feature[12]; //fear if ((Math.Abs(f1.Feature[2] - f2.Feature[2]) > 4)) //fear { if ((Math.Abs(f1.Feature[22] - f2.Feature[22]) > 8)) { if ((Math.Abs(f1.Feature[23] - f2.Feature[23]) > 8)) { if ((Math.Abs(f1.Feature[20] - f2.Feature[20]) > 10)) { if (tag_11_12 < -4) { _result = EmotionLabel.Fear.ToString(); emotion[EmotionLabel.Fear] = true; } } } } } //disgust if ((Math.Abs(f1.Feature[14] - f2.Feature[14]) > 8)) //disgust { if ((Math.Abs(f1.Feature[13] - f2.Feature[13]) > 8)) { if ((Math.Abs(f1.Feature[20] - f2.Feature[20]) > 10)) { if (tag_11_12 > 2) { _result = EmotionLabel.Disgust.ToString(); emotion[EmotionLabel.Disgust] = true; } } } } emotion.Clear(); }