示例#1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            mainBmp       = new Bitmap(Image.FromFile("./plane.bmp"));
            pb_main.Image = mainBmp;
            double[,] img = ImageTool.GetGreyScale(mainBmp);
            ImageTool.SetImage(mainBmp, img);

            int libCount = LoadLibrary("./imgLib", mainBmp.Width, mainBmp.Height, FACES_PER_PERSON);

            avg            = ImageTool.GetAvg(lib);
            difLib         = ImageTool.GetDifferenceArray(lib, avg);
            sb_lib.Maximum = libCount;
            libBmp         = new Bitmap(mainBmp.Width, mainBmp.Height);
            EigenObject eigVects = ImageTool.GetEigen(ImageTool.GetA(lib));

            ImageTool.normalize(eigVects.vectors);
            eigFaces = ImageTool.getEigenFaces(eigVects.vectors, difLib);

            libWeights = new double[lib.Length][];
            for (int i = 0; i < lib.Length; i++)
            {
                libWeights[i] = ImageTool.getWeights(eigFaces, lib[i], avg);
            }
            double[] weights = ImageTool.getWeights(eigFaces, img, avg);
            comp = ImageTool.compareWeigths(libWeights, weights);
            int p = ImageTool.smallestVal(comp);

            lb_person.Text = "Person: " + p;
            recon          = ImageTool.reconstruct(weights, eigFaces, avg);
            ImageTool.normalize(recon, 255);

            pb_lib.Image = libBmp;
            ImageTool.SetImage(libBmp, lib[p]);
            sb_lib.Value = p;
        }
示例#2
0
        public FaceRecog()
        {
            mainBmp = new Bitmap(Image.FromFile("./plane.bmp"));

            //Would be picturebox of compared image.
            //pb_main.Image = mainBmp;

            double[,] img = ImageTool.GetGreyScale(mainBmp);
            ImageTool.SetImage(mainBmp, img);

            int libCount = LoadLibrary("./imgLib", mainBmp.Width, mainBmp.Height, FACES_PER_PERSON);

            avg    = ImageTool.GetAvg(lib);
            difLib = ImageTool.GetDifferenceArray(lib, avg);

            //Would be scrollbar
            //sb_lib.Maximum = libCount;

            libBmp = new Bitmap(mainBmp.Width, mainBmp.Height);
            EigenObject eigVects = ImageTool.GetEigen(ImageTool.GetA(lib));

            ImageTool.normalize(eigVects.vectors);
            eigFaces = ImageTool.getEigenFaces(eigVects.vectors, difLib);

            libWeights = new double[lib.Length][];
            for (int i = 0; i < lib.Length; i++)
            {
                libWeights[i] = ImageTool.getWeights(eigFaces, lib[i], avg);
            }
            double[] weights = ImageTool.getWeights(eigFaces, img, avg);
            comp = ImageTool.compareWeigths(libWeights, weights);
            int p = ImageTool.smallestVal(comp);

            //Would be guess of face
            //lb_person.Text = "Person: " + p;

            recon = ImageTool.reconstruct(weights, eigFaces, avg);
            ImageTool.normalize(recon, 255);

            //would be displaying the image.
            //pb_lib.Image = libBmp;

            ImageTool.SetImage(libBmp, lib[p]);

            //Would be setting scrollbar to correct position
            //sb_lib.Value = p;
        }
示例#3
0
        private void sb_lib_Scroll(object sender, ScrollEventArgs e)
        {
            switch (display)
            {
            case DIFFERENCE:
                ImageTool.SetImage(libBmp, difLib[e.NewValue], true);
                break;

            case EIGEN:
                ImageTool.SetImage(libBmp, eigFaces[e.NewValue], true);
                break;

            case REGULAR:
            default:
                ImageTool.SetImage(libBmp, lib[e.NewValue]);
                break;
            }
            pb_lib.Image     = libBmp;
            lb_distance.Text = "Distance : " + comp[e.NewValue];
        }
示例#4
0
        private void bt_load_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "Jpeg Files (.jpg)|*.jpg|Bitmap Files (.bmp)|*.bmp|All Files (*.*)|*.*";
            ofd.FilterIndex = 1;
            ofd.Multiselect = false;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                mainBmp       = new Bitmap(Image.FromFile(ofd.FileName));
                pb_main.Image = mainBmp;
                double[,] img = ImageTool.GetGreyScale(mainBmp);
                ImageTool.SetImage(mainBmp, img);
                double[] weights = ImageTool.getWeights(eigFaces, img, avg);
                comp = ImageTool.compareWeigths(libWeights, weights);
                int p = ImageTool.smallestVal(comp);

                if (comp[p] > SAME_FACE_THRESH)
                {
                    lb_person.Text = "Person: Unknown";
                }
                else
                {
                    lb_person.Text = "Person: " + p;
                }
                recon = ImageTool.reconstruct(weights, eigFaces, avg);

                pb_lib.Image = libBmp;
                ImageTool.SetImage(libBmp, lib[p]);
                sb_lib.Value      = p;
                lb_distance.Text  = "Distance : " + comp[p];
                faceSpace         = ImageTool.difference(img, recon);
                lb_faceSpace.Text = "Face Space : " + faceSpace;
                if (faceSpace > FACE_THRESH)
                {
                    lb_faceSpace.Text += "\nNot a face";
                }
            }
        }
示例#5
0
        public string loadFace(Bitmap mainBmp)
        {
            String output;

            //display image
            //pb_main.Image = mainBmp;

            double[,] img = ImageTool.GetGreyScale(mainBmp);
            ImageTool.SetImage(mainBmp, img);
            double[] weights = ImageTool.getWeights(eigFaces, img, avg);
            comp = ImageTool.compareWeigths(libWeights, weights);
            int p = ImageTool.smallestVal(comp);

            Debug.WriteLine(comp[p] + "-----------");
            if (comp[p] > SAME_FACE_THRESH)
            {
                //lb_person.Text = "Person: Unknown";
                output = "Person: Unknown";
            }
            else
            {
                //lb_person.Text = "Person: " + p;
                output = "Person: " + p;
                ImageTool.SetImage(currentFace, lib[p]);
            }
            recon = ImageTool.reconstruct(weights, eigFaces, avg);

            //pb_lib.Image = libBmp;
            ImageTool.SetImage(libBmp, lib[p]);

            //ImageTool.SetImage(currentFace, lib[p]);

            //sb_lib.Value = p;
            //lb_distance.Text = "Distance : " + comp[p];
            faceSpace = ImageTool.difference(img, recon);
            //lb_faceSpace.Text = "Face Space : " + faceSpace;
            if (faceSpace > FACE_THRESH)
            {
                //lb_faceSpace.Text += "\nNot a face";
                output = "Not a face";
            }

            if (faceSpace < 11500)
            {
                Debug.WriteLine("--------------------" + candidateAmount);
                // candidateFace = ImageFunctions.combineImages((Bitmap)candidateFace.Clone(), mainBmp, candidateAmount);


                for (int i = 0; i < candidates.Length; i++)
                {
                    if (candidates[i] == null)
                    {
                        candidates[i]      = mainBmp;
                        candidateScores[i] = faceSpace;
                        candidateFace      = mainBmp;
                    }
                    else
                    {
                        if (faceSpace < candidateScores[i])
                        {
                            candidates[i]      = mainBmp;
                            candidateScores[i] = faceSpace;
                            candidateFace      = mainBmp;
                            break;
                        }
                    }
                }



                //if (candidateAmount < 10)
                candidateAmount++;

                //candidateFace.Save("./imgLib/face"+imageCount+".jpg", ImageFormat.Jpeg);
                //imageCount++;
            }

            return(output);
        }
示例#6
0
 private void bt_recon_Click(object sender, EventArgs e)
 {
     ImageTool.SetImage(libBmp, recon, false);
     pb_lib.Image = libBmp;
 }
示例#7
0
 private void bt_avg_Click(object sender, EventArgs e)
 {
     ImageTool.SetImage(libBmp, avg);
     pb_lib.Image = libBmp;
 }