Skip to content

Instantly share code, notes, and snippets.

@mdfarragher
Created July 19, 2019 11:29
Show Gist options
  • Save mdfarragher/49453713ed35cf867f89248c153b33f1 to your computer and use it in GitHub Desktop.
Save mdfarragher/49453713ed35cf867f89248c153b33f1 to your computer and use it in GitHub Desktop.
// detect all faces
var chips = new List<Matrix<RgbPixel>>();
var faces = new List<Rectangle>();
Console.WriteLine("Detecting faces...");
foreach (var face in detector.Operator(img))
{
// detect landmarks
var shape = predictor.Detect(img, face);
// extract normalized and rotated 150x150 face chip
var faceChipDetail = Dlib.GetFaceChipDetails(shape, 150, 0.25);
var faceChip = Dlib.ExtractImageChip<RgbPixel>(img, faceChipDetail);
// convert the chip to a matrix and store
var matrix = new Matrix<RgbPixel>(faceChip);
chips.Add(matrix);
faces.Add(face);
}
Console.WriteLine($" Found {chips.Count} faces in image");
// the rest of the code goes here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment