Ejemplo n.º 1
0
 private void btn_Favorite_Click_1(object sender, RoutedEventArgs e)
 {
     if (FavoriteFolders.Contains(SelectedFolder))
     {
         FavoriteFolders.Remove(SelectedFolder);
     }
     else
     {
         FavoriteFolders.Add(SelectedFolder);
     }
     RaiseEvent(new RoutedEventArgs(RoutedPropertyChangedEvent));
 }
Ejemplo n.º 2
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker       = (BackgroundWorker)sender;
            List <string>    checked_file = new List <string>();

            using (StreamReader reader = new StreamReader(new BufferedStream(new FileStream("checked_file.txt", FileMode.OpenOrCreate, FileAccess.Read), 512)))
            {
                while (!reader.EndOfStream)
                {
                    checked_file.Add(reader.ReadLine());
                }
            }


            using (StreamWriter writer = new StreamWriter(new BufferedStream(new FileStream("checked_file.txt", FileMode.Append, FileAccess.Write), 512)))
            {
                int i = PV_Recognizer.training_sets.Count;
                //while (!worker.CancellationPending)
                {
                    //System.Threading.Thread.Sleep(2000);
                    IEnumerable <FileInfo> files = FavoriteFolders.SelectMany(x => (new DirectoryInfo(x).GetFilesByExtensions(".jpg", ".bmp", ".png")))
                                                   .Where(x => !checked_file.Contains(x.FullName) && x.Length < 10000000);
                    foreach (FileInfo f in files)
                    {
                        CvInvoke.Resize
                        List <RecognitionModel> result = (PV_Recognizer.Recognize(new UMat(f.FullName, ImreadModes.Color)., f.FullName));
                        writer.WriteLine(f.FullName);
                        //foreach (RecognitionModel rm in result) PeopleImage.Add(rm);
                        worker.ReportProgress(0, result);

                        while ((PV_Recognizer.training_sets.Where(x => (!x.Processed)).Count() > 15) && !worker.CancellationPending)
                        {
                            System.Threading.Thread.Sleep(2000);
                        }
                        ;
                        if (PV_Recognizer.training_sets.Count - i > 30)
                        {
                            Console.WriteLine("Re-training recognizer....");
                            IEnumerable <RecognitionModel> arr = PV_Recognizer.training_sets.Where(x => x.Processed);
                            PV_Recognizer.Recognizer.Train(arr.Select(x => x.FaceImageCV).ToArray(), arr.Select(x => x.LabelInt).ToArray());
                            i = PV_Recognizer.training_sets.Count;
                            Console.WriteLine("Training completed!");
                        }
                    }
                }
            }
        }