SHARE
TWEET

Untitled

a guest Oct 10th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using Emgu.CV;
  11. using Emgu.CV.CvEnum;
  12. using Emgu.CV.Structure;
  13. using Emgu.CV.Cvb;
  14.  
  15. namespace WindowsFormsApplication3
  16. {
  17.  
  18.     public partial class Form1 : Form
  19.     {
  20.        
  21.  
  22.         public Form1()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.  
  27.         private void button1_Click(object sender, EventArgs e)
  28.         {
  29.             OpenFileDialog ok = new OpenFileDialog();
  30.             Image img = null;
  31.             string imgName = "";
  32.  
  33.             if (ok.ShowDialog() == DialogResult.OK)
  34.             {
  35.                 img = Image.FromFile(ok.FileName);
  36.                 General.imgName = ok.FileName;
  37.                 pictureBox1.Image = img;
  38.             }
  39.         }
  40.  
  41.         private void button2_Click(object sender, EventArgs e)
  42.         {
  43.  
  44.             if (General.imgName == "")
  45.             {
  46.                 return;
  47.             }
  48.  
  49.             Image<Bgr, byte> image = new Image<Bgr, byte>(new Bitmap(pictureBox1.Image));
  50.             Image<Gray, Byte> grayImage = image.Convert<Gray, Byte>();
  51.  
  52.            
  53.             var eyes = grayImage.DetectHaarCascade(General.eyeCascade)[0];
  54.  
  55.             foreach (var eye in eyes)
  56.             {
  57.                 image.Draw(eye.rect, new Bgr(0, 0, 255), 3);
  58.             }
  59.  
  60.             if (eyes.Count() == 0)
  61.             {
  62.                 imageBox1.Image = image;
  63.                 return;
  64.             }
  65.  
  66.             var faces = grayImage.DetectHaarCascade(General.faceCascade)[0];
  67.  
  68.             foreach (var face in faces)
  69.             {
  70.                 image.Draw(face.rect, new Bgr(255, 255, 255), 10);
  71.             }
  72.  
  73.             imageBox1.Image = image;
  74.  
  75.         }
  76.     }
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top