Esempio n. 1
0
        private void FaceRecognition_Click(object sender, EventArgs e)
        {
            var Dir = Directory.GetFiles(PathToLoadFolder).ToList <string>();

            var Pictures = from Pic in Dir
                           where Pic.Substring(Pic.Length - 3, 3) == "jpg"
                           select Pic;

            var    Tab              = new int[Pictures.Count()];
            int    RowCount         = 3;
            int    ColCount         = 3;
            int    counter          = 0;
            int?   min              = null;
            string PersonRecognized = "Blad programu";

            int[, ][] Shades = new int[RowCount, ColCount][];
            Bitmap[,] BitmapMatrix = new Bitmap[RowCount, ColCount];
            DividePicture(imageAfter, BitmapMatrix);
            ArrayHistogramValues(BitmapMatrix, Shades, RowCount, ColCount);


            Bitmap bitmap;

            AdvancedSimilarity[] Base = new AdvancedSimilarity[Pictures.Count()];

            foreach (var item in Pictures)
            {
                bitmap             = (Bitmap)Image.FromFile(item);
                Base[counter]      = new AdvancedSimilarity(RowCount, ColCount);
                Base[counter].Name = item.Substring(PathToLoadFolder.Length + 1, item.Length - PathToLoadFolder.Length - 5);
                DividePicture(bitmap, Base[counter].BitmapParts);
                ArrayHistogramValues(Base[counter].BitmapParts, Base[counter].Shades, RowCount, ColCount);
                var calc = ComparePicturesShades(Shades, Base[counter].Shades, RowCount, ColCount);
                Tab[counter] = SimilarityScale(calc, RowCount, ColCount);
                if (min == null)
                {
                    min = Tab[counter];
                }
                else if (Tab[counter] < min)
                {
                    min = Tab[counter];
                    PersonRecognized = Base[counter].Name;
                }
                counter++;
            }

            Debug.WriteLine($"Person from image {PersonRecognized} is recognised");
        }
Esempio n. 2
0
        private void CompareAndSaveResults_Click(object sender, EventArgs e)
        {
            var SelectedFolder = Directory.GetFiles(PathToLoadFolder);
            int Files          = SelectedFolder.Length;

            AdvancedSimilarity[] Results = new AdvancedSimilarity[Files];
            string Name;
            int    Index;
            int    RowCount = 3;
            int    ColCount = 3;

            for (int i = 0; i < Files; i++)
            {
                Results[i] = new AdvancedSimilarity(RowCount, ColCount);
            }
            foreach (var Item in SelectedFolder)
            {
                Name  = Item.Substring(PathToLoadFolder.Length + 1, Item.Length - PathToLoadFolder.Length - 5);
                Index = Int32.Parse(Name) - 1;

                Results[Index].Name = Name;
                DividePicture((Bitmap)Bitmap.FromFile(Item), Results[Index].BitmapParts);
                ArrayHistogramValues(Results[Index].BitmapParts, Results[Index].Shades, RowCount, ColCount);
            }

            for (int i = 0; i < Files; i++)
            {
                Debug.WriteLine(Results[i].Name);
            }

            float[,] CrossValidation = new float[Results.Length, Results.Length];
            int[, ][] Sum = new int[RowCount, ColCount][];

            for (int i = 0; i < Results.Length; i++)
            {
                for (int j = 0; j < Results.Length; j++)
                {
                    Sum = ComparePicturesShades(Results[i].Shades, Results[j].Shades, RowCount, ColCount);
                    CrossValidation[i, j] = ((float)(SimilarityScale(Sum, RowCount, ColCount)) / 77760) * 100;        // hard coded 77760 (workes only with pic 320x243)
                    /*CrossValidation[i, j] = SimilarityScale(Sum, RowCount, ColCount);*/
                }
            }

            string Text;

            Text = "Index\t";
            File.AppendAllText(PathForCSV, Text, Encoding.UTF8);
            Text = null;
            for (int i = 1; i <= Results.Length; i++)
            {
                Text += i.ToString() + ",\t\t";
            }
            Text += Environment.NewLine;
            File.AppendAllText(PathForCSV, Text, Encoding.UTF8);

            for (int i = 0; i < Results.Length; i++)
            {
                Text = (i + 1).ToString() + ",\t";
                for (int j = 0; j < Results.Length; j++)
                {
                    if (CrossValidation[i, j].ToString().Length < 7)
                    {
                        Text += CrossValidation[i, j].ToString() + ",\t\t";
                    }

                    else
                    {
                        Text += CrossValidation[i, j].ToString() + ",\t";
                    }
                }

                Text += Environment.NewLine;
                File.AppendAllText(PathForCSV, Text, Encoding.UTF8);
            }
            Debug.WriteLine("Koniec");
        }