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"; } } }
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); }