Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Im doing the project for eye blink detection using opencv in c#.i detect eye and face but not eye blink.so any one help me to detect eye blink..
here is the code
C#
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Emgu.CV.CvEnum;

namespace EyeDetection
{
    public partial class Form1 : Form
    {
        private Capture _capture;
        private HaarCascade _faces;
        private HaarCascade _eyes;
        int xMax;
        int yMax;
        public Form1()
        {
            InitializeComponent();
            _capture = new Capture();
            _faces=new HaarCascade("C:\\Users\\subha\\Documents\\Visual Studio 2010\\Projects\\EyeDetection\\EyeDetection\\haarcascade_frontalface_default.xml");
            _eyes = new HaarCascade("C:\\Users\\subha\\Documents\\Visual Studio 2010\\Projects\\EyeDetection\\EyeDetection\\haarcascade_eye.xml");
            Application.Idle += ProcessFrame;
            _capture.Start();
            
            
        }  
        
        private void ProcessFrame(object sender, EventArgs arg)
      {
          try
          {
              Image<bgr,> frame = _capture.QueryFrame();
              Image<gray,> grayFrame = frame.Convert<gray,>();

              grayFrame._EqualizeHist();


              MCvAvgComp[][] facesDetected = grayFrame.DetectHaarCascade(_faces, 1.1, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.FIND_BIGGEST_OBJECT, new Size(20, 20));

              if (facesDetected[0].Length == 1)
              {
                  MCvAvgComp face = facesDetected[0][0];
                  Int32 yCoordStartSearchEyes = face.rect.Top + (face.rect.Height * 3 / 11);
                  Point startingPointSearchEyes = new Point(face.rect.X, yCoordStartSearchEyes);
                  Point endingPointSearchEyes = new Point((face.rect.X + face.rect.Width), yCoordStartSearchEyes);

                  Size searchEyesAreaSize = new Size(face.rect.Width, (face.rect.Height * 2 / 9));
                  Point lowerEyesPointOptimized = new Point(face.rect.X, yCoordStartSearchEyes + searchEyesAreaSize.Height);
                  Size eyeAreaSize = new Size(face.rect.Width / 2, (face.rect.Height * 2 / 9));
                  Point startingLeftEyePointOptimized = new Point(face.rect.X + face.rect.Width / 2, yCoordStartSearchEyes);

                  Rectangle possibleROI_eyes = new Rectangle(startingPointSearchEyes, searchEyesAreaSize);
                  Rectangle possibleROI_rightEye = new Rectangle(startingPointSearchEyes, eyeAreaSize);
                  Rectangle possibleROI_leftEye = new Rectangle(startingLeftEyePointOptimized, eyeAreaSize);

               

                  grayFrame.ROI = possibleROI_leftEye;
                  MCvAvgComp[][] leftEyesDetected = grayFrame.DetectHaarCascade(_eyes, 1.15, 0, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20));
                  grayFrame.ROI = Rectangle.Empty;

                  grayFrame.ROI = possibleROI_rightEye;
                  MCvAvgComp[][] rightEyesDetected = grayFrame.DetectHaarCascade(_eyes, 1.15, 0, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20));
                  grayFrame.ROI = Rectangle.Empty;


                  if (leftEyesDetected[0].Length != 0 && rightEyesDetected[0].Length != 0)
                  {

                      frame.Draw(face.rect, new Bgr(Color.Violet), 2);
                      grayFrame.ROI = possibleROI_leftEye;
                      CircleF[] leftEyecircles = grayFrame.HoughCircles(new Gray(180), new Gray(70), 5.0, 10.0, 1, 200)[0];
                      grayFrame.ROI = Rectangle.Empty;
                    

                      grayFrame.ROI = possibleROI_rightEye;
                      CircleF[] rightEyecircles = grayFrame.HoughCircles(new Gray(180), new Gray(70), 5.0, 10.0, 1, 200)[0];
                      grayFrame.ROI = Rectangle.Empty;

                     
                      foreach (MCvAvgComp eyeLeft in leftEyesDetected[0])
                      {
                          Rectangle eyeRect = eyeLeft.rect;
                          eyeRect.Offset(startingLeftEyePointOptimized.X, startingLeftEyePointOptimized.Y);
                          frame.Draw(eyeRect, new Bgr(Color.Red), 2);
                      }
                      foreach (MCvAvgComp eyeRight in rightEyesDetected[0])
                      {
                          Rectangle eyeRect = eyeRight.rect;
                        
                          eyeRect.Offset(startingPointSearchEyes.X, startingPointSearchEyes.Y);
                          frame.Draw(eyeRect, new Bgr(Color.Red), 2);
                      }

                  }
                  DisplayBox.Image = frame.Bitmap;

              }
          }
          catch (Exception ex)
          {

              MessageBox.Show(ex.Message);
          }         
        }

        }   
        }
Posted
Updated 18-Sep-14 21:02pm
v2

1 solution

Why not start here EmguCV: Code Gallery[^]

or here Support and Services[^]

And to be realistic. How many users here do you think have EmguCV installed on their computers and are willing to debug your code?

And if you want the code this badly you either have to write it yourself or pay someone to do it for you.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Sep-14 4:28am    
Agree, a 5.
—SA
George Jonsson 19-Sep-14 4:32am    
Thanks Sergey.
Seems like a lot of EmguCV questions lately. And they do have a support mail address.
Sergey Alexandrovich Kryukov 19-Sep-14 4:35am    
It means that we look less threatening to the inquirers than those customer services. They prefer asking us. Aren't we well too nice? :-)
—SA
George Jonsson 19-Sep-14 4:41am    
So no more Mr. Nice Guy. :D
Sergey Alexandrovich Kryukov 19-Sep-14 10:27am    
:-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900