ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Protected Member Functions | List of all members
ImageResizer.Plugins.RedEye.EyeDetection Class Reference
Inheritance diagram for ImageResizer.Plugins.RedEye.EyeDetection:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.RedEye.EyeDetection:
Collaboration graph
[legend]

Protected Member Functions

override List< ObjRectDetectFeatures (IplImage img, CvMemStorage storage)
 Detects features on a grayscale image. More...
 

Detailed Description

Definition at line 37 of file EyeDetection.cs.

Member Function Documentation

override List<ObjRect> ImageResizer.Plugins.RedEye.EyeDetection.DetectFeatures ( IplImage  img,
CvMemStorage  storage 
)
inlineprotected

Detects features on a grayscale image.

Parameters
img
storage
Returns

Definition at line 57 of file EyeDetection.cs.

57  {
58  List<ObjRect> eyes = new List<ObjRect>();
59 
60  //Detect faces
61  Stopwatch watch = Stopwatch.StartNew();
62  CvAvgComp[] faces = Cv.HaarDetectObjects(img, Cascades["FaceCascade"], storage, 1.0850, 2, 0, new CvSize(30, 30)).ToArrayAndDispose();
63  watch.Stop();
64  Debug.WriteLine("face detection time = " + watch.ElapsedMilliseconds);
65 
66  watch.Reset(); watch.Start();
67 
68  //If there are no faces, look for large eye pairs
69  if (faces.Length == 0) {
70  CvAvgComp[] pairs = Cv.HaarDetectObjects(img, Cascades["EyePair45"], storage, 1.0850, 2, 0, new CvSize(img.Width / 4, img.Width / 20)).ToArrayAndDispose();
71  if (pairs.Length > 0) {
72  //TODO!!! Uncomment and test now that CompareByNeighbors sorts correctly
73  //Array.Sort<CvAvgComp>(pairs, CompareByNeighbors);
74  //Take the 1st most likely that actually contains eyes. We don't want to evaluate multiple eye pairs when there are no faces.
75  //If there are pairs, evalutate them all. Finding eyes within multiple pairs is unlikely
76  foreach (CvAvgComp pair in pairs) {
77  var results = DetectFeaturesInPair(img, storage, pair);
78  eyes.AddRange(results);
79  if (results.Count > 0) break;
80  }
81  }
82  }
83 
84  //For each face...
85  foreach (CvAvgComp face in faces) {
86  eyes.AddRange(DetectFeaturesInFace(img, storage, face));
87  }
88 
89  watch.Stop();
90  Debug.WriteLine("eye detection time = " + watch.ElapsedMilliseconds);
91  return eyes;
92  }

The documentation for this class was generated from the following file: