private void btnOpenPhoto_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { FSDK.CImage image = new FSDK.CImage(openFileDialog1.FileName); // resize image to fit the window width double ratio = System.Math.Min((pictureBox1.Width + 0.4) / image.Width, (pictureBox1.Height + 0.4) / image.Height); image = image.Resize(ratio); Image frameImage = image.ToCLRImage(); Graphics gr = Graphics.FromImage(frameImage); FSDK.TFacePosition facePosition = image.DetectFace(); if (0 == facePosition.w) MessageBox.Show("No faces detected", "Face Detection"); else { int left = facePosition.xc - (int)(facePosition.w*0.6f); int top = facePosition.yc - (int)(facePosition.w*0.5f); gr.DrawRectangle(Pens.LightGreen, left, top, (int)(facePosition.w*1.2), (int)(facePosition.w*1.2)); FSDK.TPoint[] facialFeatures = image.DetectFacialFeaturesInRegion(ref facePosition); int i = 0; foreach (FSDK.TPoint point in facialFeatures) gr.DrawEllipse((++i > 2) ? Pens.LightGreen : Pens.Blue, point.x, point.y, 3, 3); gr.Flush(); } // display image pictureBox1.Image = frameImage; pictureBox1.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception"); } } }
private void detect_button_Click(object sender, EventArgs e) { var sampes = Directory.GetFiles("C:\\Projects\\misoi\\bsuir-misoi\\Presentation.WindowsForms\\Samples"); foreach (var sample in sampes) { try { FSDK.CImage image = new FSDK.CImage(sample); // resize image to fit the window width double ratio = System.Math.Min((resultPictureBox.Width + 0.4) / image.Width, (resultPictureBox.Height + 0.4) / image.Height); image = image.Resize(ratio); FSDK.TFacePosition facePosition = image.DetectFace(); if (0 == facePosition.w) MessageBox.Show("No faces detected", "Face Detection"); else { FSDK.TPoint[] facialFeatures = image.DetectFacialFeaturesInRegion(ref facePosition); int i = 0; using (var writer = File.AppendText("sasi.txt")) { foreach (FSDK.TPoint point in facialFeatures) { writer.Write((double)(point.x - facePosition.xc)/facePosition.w + "," + (double)(point.y - facePosition.yc)/facePosition.w + ","); } writer.Write("Happy"); writer.WriteLine(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception"); } } }
private void openBtn_Click(object sender, EventArgs e) { using (var dlg = new OpenFileDialog()) { dlg.Title = "Open Image"; dlg.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG"; if (dlg.ShowDialog() == DialogResult.OK) { sourcePictureBox.Image = new Bitmap(dlg.FileName); resultPictureBox.Image = null; try { FSDK.CImage image = new FSDK.CImage(dlg.FileName); // resize image to fit the window width double ratio = System.Math.Min((resultPictureBox.Width + 0.4) / image.Width, (resultPictureBox.Height + 0.4) / image.Height); image = image.Resize(ratio); Image frameImage = image.ToCLRImage(); Graphics gr = Graphics.FromImage(frameImage); FSDK.TFacePosition facePosition = image.DetectFace(); if (0 == facePosition.w) MessageBox.Show("No faces detected", "Face Detection"); else { int left = facePosition.xc - facePosition.w / 2; int top = facePosition.yc - facePosition.w / 2; gr.DrawRectangle(Pens.LightGreen, left, top, facePosition.w, facePosition.w); FSDK.TPoint[] facialFeatures = image.DetectFacialFeaturesInRegion(ref facePosition); int i = 0; using (var writer = File.AppendText("sasi.txt")) { foreach (FSDK.TPoint point in facialFeatures) { gr.DrawEllipse((++i > 2) ? Pens.LightGreen : Pens.Blue, point.x, point.y, 3, 3); writer.Write((point.x - facePosition.xc) + "," + (point.y - facePosition.yc) + ","); } writer.Write("Happy"); writer.WriteLine(); } gr.Flush(); } // display image resultPictureBox.Image = frameImage; resultPictureBox.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception"); } } } }