/// <summary> /// Processor initializer /// <param name="facesCascadeData">String with cascade XML for face detection, must be defined</param> /// <param name="eyesCascadeData">String with cascade XML for eyes detection, can be null</param> /// <param name="shapeData">Binary data with trained shape predictor for 68-point face landmarks recognition, can be empty or null</param> /// </summary> public virtual void Initialize(string facesCascadeData, string eyesCascadeData, byte[] shapeData = null) { // face detector - the key thing here if (null == facesCascadeData || facesCascadeData.Length == 0) { throw new Exception("FaceProcessor.Initialize: No face detector cascade passed, with parameter is required"); } FileStorage storageFaces = new FileStorage(facesCascadeData, FileStorage.Mode.Read | FileStorage.Mode.Memory); cascadeFaces = new CascadeClassifier(); if (!cascadeFaces.Read(storageFaces.GetFirstTopLevelNode())) { throw new System.Exception("FaceProcessor.Initialize: Failed to load faces cascade classifier"); } // eyes detector if (null != eyesCascadeData) { FileStorage storageEyes = new FileStorage(eyesCascadeData, FileStorage.Mode.Read | FileStorage.Mode.Memory); cascadeEyes = new CascadeClassifier(); if (!cascadeEyes.Read(storageEyes.GetFirstTopLevelNode())) { throw new System.Exception("FaceProcessor.Initialize: Failed to load eyes cascade classifier"); } } // shape detector if (null != shapeData && shapeData.Length > 0) { shapeFaces = new ShapePredictor(); shapeFaces.LoadData(shapeData); } }