ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Protected Member Functions | Properties | List of all members
ImageResizer.Plugins.Faces.FaceDetection Class Reference

Provides a simple API for face detection More...

Inheritance diagram for ImageResizer.Plugins.Faces.FaceDetection:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.Faces.FaceDetection:
Collaboration graph
[legend]

Protected Member Functions

override List< FaceDetectFeatures (IplImage img, CvMemStorage storage)
 Detects features on a grayscale image. More...
 
- Protected Member Functions inherited from ImageResizer.Plugins.Faces.FeatureDetectionBase< T >
int CompareByNeighbors (CvAvgComp a, CvAvgComp b)
 

Properties

int MinFaces haarcascade_frontalface_default.xml" [get, set]
 The minimum number of faces expected More...
 
int MaxFaces [get, set]
 The maximum number of faces wanted More...
 
float MinSizePercent [get, set]
 The smallest face that will be detected, represented in a 1..100 percentage of the (smaller of width and height). Defaults to 3 percent (3.0f) More...
 
int ConfidenceLevelThreshold [get, set]
 The minimum number of agreeing matches required for a face rectangle to be returned. This rule isn't applied if we don't have [MinFaces] number of faces. More...
 
int MinConfidenceLevel [get, set]
 The minimum number of agreeing matches required for a face rectangle to be evaluated More...
 
double ExpandX [get, set]
 The percentage by which to expand each face rectangle horizontally after detection. To expand 5% each side, set to 0.1 More...
 
double ExpandY [get, set]
 The percentage by which to expand each face rectangle vertically after detection. To expand 20% on the top and bottom, set to 0.4 More...
 

Additional Inherited Members

- Public Member Functions inherited from ImageResizer.Plugins.Faces.FeatureDetectionBase< T >
 FeatureDetectionBase (string xmlFolder)
 
List< T > DetectFeatures (Bitmap b)
 
void Dispose ()
 Disposes all loaded cascades More...
 
- Protected Attributes inherited from ImageResizer.Plugins.Faces.FeatureDetectionBase< T >
List< string > searchFolders = new List<string>() { }
 
Dictionary< string, string > fileNames = new Dictionary<string,string>(){ }
 
Dictionary< string, string > Files = null
 
Dictionary< string,
CvHaarClassifierCascade > 
Cascades = null
 
int scaledBounds = 1000
 Large images will be scaled down to less than scaledBounds X scaledBounds for feature detection. Defaults to 1000 More...
 

Detailed Description

Provides a simple API for face detection

Definition at line 30 of file FaceDetection.cs.

Member Function Documentation

override List<Face> ImageResizer.Plugins.Faces.FaceDetection.DetectFeatures ( IplImage  img,
CvMemStorage  storage 
)
inlineprotectedvirtual

Detects features on a grayscale image.

Parameters
img
storage
Returns

Implements ImageResizer.Plugins.Faces.FeatureDetectionBase< T >.

Definition at line 87 of file FaceDetection.cs.

87  {
88  //Determine minimum face size
89  var minSize = (int)Math.Round((double)MinSizePercent / 100.0 * Math.Min(img.Width, img.Height));
90 
91 
92  //Detect faces (frontal). TODO: side
93  Stopwatch watch = Stopwatch.StartNew();
94  CvAvgComp[] faces = Cv.HaarDetectObjects(img, Cascades["FaceCascade"], storage, 1.0850, MinConfidenceLevel, 0, new CvSize(minSize, minSize)).ToArrayAndDispose();
95  watch.Stop();
96  Debug.WriteLine("Face detection time = " + watch.ElapsedMilliseconds);
97 
98  //Sort by accuracy
99  Array.Sort<CvAvgComp>(faces, CompareByNeighbors);
100 
101  //Convert into feature objects list
102  List<Face> features = new List<Face>(faces.Length);
103  foreach (CvAvgComp face in faces) features.Add(new Face(PolygonMath.ScaleRect(face.Rect.ToRectangleF(),ExpandX,ExpandY), face.Neighbors));
104 
105  //Unless we're below MinFaces, filter out the low confidence matches.
106  while (features.Count > MinFaces && features[features.Count - 1].Accuracy < ConfidenceLevelThreshold) features.RemoveAt(features.Count - 1);
107 
108 
109  //Never return more than [MaxFaces]
110  return (features.Count > MaxFaces) ? features.GetRange(0, MaxFaces) : features;
111  }
double ExpandY
The percentage by which to expand each face rectangle vertically after detection. To expand 20% on th...
static RectangleF ScaleRect(RectangleF rect, double ExpandX, double ExpandY)
Expands the given rectangle using the specified scale multipliers, leaving it centered ...
Definition: PolygonMath.cs:823
double ExpandX
The percentage by which to expand each face rectangle horizontally after detection. To expand 5% each side, set to 0.1
int ConfidenceLevelThreshold
The minimum number of agreeing matches required for a face rectangle to be returned. This rule isn&#39;t applied if we don&#39;t have [MinFaces] number of faces.
Defines a collection of utility functions for manipulating polygons. These functions may be (re)moved...
Definition: PolygonMath.cs:13
int MaxFaces
The maximum number of faces wanted
int MinFaces
The minimum number of faces expected
float MinSizePercent
The smallest face that will be detected, represented in a 1..100 percentage of the (smaller of width ...
int MinConfidenceLevel
The minimum number of agreeing matches required for a face rectangle to be evaluated ...

Property Documentation

int ImageResizer.Plugins.Faces.FaceDetection.ConfidenceLevelThreshold
getset

The minimum number of agreeing matches required for a face rectangle to be returned. This rule isn't applied if we don't have [MinFaces] number of faces.

Definition at line 63 of file FaceDetection.cs.

double ImageResizer.Plugins.Faces.FaceDetection.ExpandX
getset

The percentage by which to expand each face rectangle horizontally after detection. To expand 5% each side, set to 0.1

Definition at line 73 of file FaceDetection.cs.

double ImageResizer.Plugins.Faces.FaceDetection.ExpandY
getset

The percentage by which to expand each face rectangle vertically after detection. To expand 20% on the top and bottom, set to 0.4

Definition at line 78 of file FaceDetection.cs.

int ImageResizer.Plugins.Faces.FaceDetection.MaxFaces
getset

The maximum number of faces wanted

Definition at line 51 of file FaceDetection.cs.

int ImageResizer.Plugins.Faces.FaceDetection.MinConfidenceLevel
getset

The minimum number of agreeing matches required for a face rectangle to be evaluated

Definition at line 68 of file FaceDetection.cs.

int ImageResizer.Plugins.Faces.FaceDetection.MinFaces haarcascade_frontalface_default.xml"
getset

The minimum number of faces expected

Definition at line 47 of file FaceDetection.cs.

float ImageResizer.Plugins.Faces.FaceDetection.MinSizePercent
getset

The smallest face that will be detected, represented in a 1..100 percentage of the (smaller of width and height). Defaults to 3 percent (3.0f)

Definition at line 57 of file FaceDetection.cs.


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