private static void GeneratePerson(string person) { if (Directory.Exists(PathHelper.PersonTrainPath(person))) { return; } Directory.CreateDirectory(PathHelper.PersonTrainPath(person)); Dictionary <string, int> timestamps = TimeStampReader.GetTimeStamps(person); Dictionary <string, int> emotions = ImageDisplay.GetEmotionDictionary(); if (timestamps == null) { return; } foreach (var item in timestamps) { if (item.Key.StartsWith("sample")) { DirectoryInfo taskDirectory = new DirectoryInfo(PathHelper.FrontalSamplesPath(person)); var taskFiles = taskDirectory.GetFiles("*.jpeg").Where(p => p.Name.StartsWith(item.Value + "_")); if (taskFiles.Count() > 0) { var first = taskFiles.ToArray()[0]; File.Copy(first.FullName, PathHelper.PersonTrainPath(person) + emotions[item.Key] + "_" + item.Value + ".jpeg"); } } } }
public static void AddImage(string person, string emotion, int frame) { DirectoryInfo taskDirectory = new DirectoryInfo(PathHelper.FrontalSamplesPath(person)); var taskFiles = taskDirectory.GetFiles("*.jpeg").Where(p => p.Name.StartsWith(frame + "_")); if (taskFiles.Count() > 0) { Dictionary <string, int> emotions = ImageDisplay.GetEmotionDictionary(); var first = taskFiles.ToArray()[0]; File.Copy(first.FullName, PathHelper.PersonTrainPath(person) + emotions[emotion] + "_" + frame + ".jpeg"); } }
public static Dictionary <string, int> GetTimeStamps(string person) { Dictionary <string, int> timestamps = new Dictionary <string, int>(); if (!File.Exists(PathHelper.TimeStampsPath(person))) { return(null); } // INITIAL TIME STAMPS foreach (var emotion in ImageDisplay.GetEmotionDictionary()) { timestamps[emotion.Key] = 0; } string fileString = File.ReadAllLines(PathHelper.TimeStampsPath(person))[0]; Dictionary <string, double[]> dictionary = JsonConvert.DeserializeObject (fileString, typeof(Dictionary <string, double[]>)) as Dictionary <string, double[]>; foreach (var item in dictionary) { timestamps[item.Key] = ( int )item.Value[0]; } // NEW TIME STAMPS DirectoryInfo taskDirectory = new DirectoryInfo(PathHelper.PersonTrainPath(person)); FileInfo[] files = taskDirectory.GetFiles("*.jpeg"); Dictionary <string, int> emotionDictionary = ImageDisplay.GetEmotionDictionary(); foreach (FileInfo file in files) { string[] emotion_frame = file.Name.Split('_'); string emotion = emotionDictionary.FirstOrDefault( x => x.Value == Int32.Parse(emotion_frame[0])) .Key; timestamps[emotion] = Int32.Parse(emotion_frame[1].Replace(".jpeg", "")); } return(timestamps); }
public static void RemoveImage(string person, string emotion, int frame) { Dictionary <string, int> emotions = ImageDisplay.GetEmotionDictionary(); File.Delete(PathHelper.PersonTrainPath(person) + emotions[emotion] + "_" + frame + ".jpeg"); }