Beispiel #1
0
        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");
                    }
                }
            }
        }
Beispiel #2
0
        public static BitmapImage GetImageFromTrain(string person, string emotion)
        {
            DirectoryInfo taskDirectory = new DirectoryInfo(PathHelper.PersonTrainPath(person));

            if (emotionDictioary == null)
            {
                GetEmotionDictionary();
            }
            int number    = emotionDictioary[emotion];
            var taskFiles = taskDirectory.GetFiles("*.jpeg").Where(p => p.Name.StartsWith(number.ToString() + "_"));

            if (taskFiles.Count() > 0)
            {
                var first = taskFiles.ToArray()[0];

                BitmapImage logo = new BitmapImage();
                logo.BeginInit();
                logo.UriSource = new Uri(first.FullName);
                logo.EndInit();
                return(logo);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        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");
            }
        }
Beispiel #4
0
        public static bool ImageExists(string person, string emotion, int frame)
        {
            DirectoryInfo taskDirectory = new DirectoryInfo(PathHelper.PersonTrainPath(person));

            if (emotionDictioary == null)
            {
                GetEmotionDictionary();
            }
            int    numberEmotion = emotionDictioary[emotion];
            string fileName      = numberEmotion + "_" + frame;
            var    taskFiles     = taskDirectory.GetFiles("*.jpeg").Where(p => p.Name.StartsWith(fileName));

            return(taskFiles.Count() > 0);
        }
        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);
        }
Beispiel #6
0
        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");
        }