-
Notifications
You must be signed in to change notification settings - Fork 125
Suggestion: Include sample for Facemark? #10
Description
It would be nice to include a sample of the Facemark face landmark detector, as there seems to be no examples to be found on the web anywhere! Trying to translate the example from the OpenCV source into OpenCvSharp seems to lead to a crash when calling fit(), so any expertise you can offer in terms of how this should be done would be much appreciated!
Here's my current (broken) code:
'''
// Load the source image and convert to greyscale
Mat input = new Mat(Path.Combine(Application.streamingAssetsPath, "aa.png"), ImreadModes.Color);
Mat grey = new Mat();
Cv2.CvtColor(input, grey, ColorConversionCodes.BGR2GRAY);
// This works, so the greyscale image is being created ok
// Cv2.ImShow("Greyscale", grey);
// Find faces in the image
var classifier = new CascadeClassifier(Path.Combine(Application.streamingAssetsPath, "haarcascade_frontalface_alt.xml"));
OpenCvSharp.Rect[] facesRects = classifier.DetectMultiScale(grey);
// This works, so faces are being found by the HAAR detector
// Debug.Log(string.Format("{0} faces detected:", facesRects.Length));
// for (int i = 0; i < facesRects.Length; i++) {
//`Debug.Log(facesRects[i].ToString());
//}
// Create a new facemark instance and load the model
OpenCvSharp.Face.Facemark facemark = OpenCvSharp.Face.FacemarkLBF.Create();
facemark.LoadModel(Path.Combine(Application.streamingAssetsPath, "lbfmodel.yaml"));
// Create inputs for the fit function
InputArray facesArray = InputArray.Create(facesRects);
Mat landmarks = new Mat();
// Following line causes a crash :(
facemark.Fit(grey, facesArray, landmarks);