public string FindFace() { string ex = Path.GetExtension(lbFileName.Text); var uniqueName = Guid.NewGuid(); var myUniqueFileName = string.Format(@"{0}{1}", uniqueName, ex); Console.WriteLine("Answer ",myUniqueFileName); Bitmap InputImage = new Bitmap(lbFileName.Text); InputImage.Save(path + myUniqueFileName); //System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter(myUniqueFileName); //Image img = (Image)converter.ConvertFrom(byteArrayIn); using (Image<Bgr, Byte> image = new Image<Bgr, byte>(myUniqueFileName)) { HaarCascade haar = new HaarCascade("haarcascade_frontalface_alt2.xml"); // there's only one channel (greyscale), hence the zero index //var faces = nextFrame.DetectHaarCascade(haar)[0]; Image<Gray, byte> grayframe = image.Convert<Gray, byte>(); var faces = grayframe.DetectHaarCascade( haar, 1.4, 4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(image.Width / 25, image.Height / 25) )[0]; if (faces.Length != 0) { //foreach (var face in faces) //{ var FaceFileName = string.Format(@"{0}{1}", uniqueName, ex); // image.Draw(face.rect, new Bgr(0, 255, 0), 3); image.ROI = faces[0].rect; string FaceImage = path + "Temp\\" + FaceFileName; image.Save(FaceImage); ImgFace.Image = Image.FromFile(FaceImage); MessageBox.Show("Face Detected", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //} } else { MessageBox.Show("No Face In this Image", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); lbFileName.Text = "No File Choosen"; this.pictureBox1.BackgroundImage = global::FaceAnnotation.Properties.Resources.no_image_selected; } File.Delete(path + myUniqueFileName); return uniqueName.ToString(); } }
path + myUniqueFileName
string result = Path.Combine(path, myUniqueFileName);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)