/// <summary> /// Get emotion features using distances and wrinkles /// </summary> /// <param name="ImageMat">Image on which distances need to calculate</param> /// <param name="faces">Rectangles of faces</param> /// <param name="index">Index of images in case of multiple images</param> /// <returns>Returns the list of distances</returns> public EmotionTrainingMLModel FindEmotions(Mat ImageMat, List <Rectangle> faces, int index) { EmotionTrainingMLModel dataModel = new EmotionTrainingMLModel(); if (faces.Count > 0) { Mat shortImage = new Mat(ImageMat, faces[0]); CvInvoke.Resize(shortImage, shortImage, new Size(320, 240), 0, 0, Inter.Linear); faces = new List <Rectangle>(); faces.Add(new Rectangle(0, 0, shortImage.Width, shortImage.Height)); List <double> distances = findDistances(shortImage, faces, index); double noseWrinkles = findWrinkles(shortImage, onNose); double betweenEyesWrinkles = findWrinkles(shortImage, betweenEyes); dataModel = new EmotionTrainingMLModel(); for (int i = 0; i < 14; i++) { var value = distances.ElementAt(i); PropertyInfo propertyInfo = dataModel.GetType().GetProperty(listOfDistances[i]); propertyInfo.SetValue(dataModel, value, null); } dataModel.noseWrinkles = noseWrinkles; dataModel.betweenEyesWrinkles = betweenEyesWrinkles; dataModel.Label = ""; //emotions= EDRMLMain.getInstance().getCalculatedEmotions(dataModel); } return(dataModel); }
/// <summary> /// Train system using multiple files and then call ML algorithm to train /// </summary> /// <param name="files">List of file names to train machiene</param> /// <returns>Returns a model of ML layer</returns> public List <EmotionTrainingMLModel> TrainSystemForEmotion(string[] files) { using (Logger logger = new Logger()) { List <EmotionTrainingMLModel> emotionList = new List <EmotionTrainingMLModel>(); int index = 0; foreach (string file in files) { logger.LogIntoFile(Log.logType.INFO, (string)ConstantsLoader.getInstance().getValue(EnumConstant.emotionTrainingMessage)); Mat image = new Mat(file); List <Rectangle> faces = new List <Rectangle>(); faces = FDIPMAin.DetectFace(image); if (faces.Count > 0) { EDRFeatureExtraction featureExtracter = new EDRFeatureExtraction(); Mat shortImage = new Mat(image, faces[0]); CvInvoke.Resize(shortImage, shortImage, new Size(320, 240), 0, 0, Inter.Linear); faces = new List <Rectangle>(); faces.Add(new Rectangle(0, 0, shortImage.Width, shortImage.Height)); List <double> distances = featureExtracter.findDistances(shortImage, faces, index); EmotionTrainingMLModel dataModel = new EmotionTrainingMLModel(); for (int i = 0; i < 14; i++) { var value = distances.ElementAt(i); PropertyInfo propertyInfo = dataModel.GetType().GetProperty(listOfDistances[i]); propertyInfo.SetValue(dataModel, value, null); } dataModel.noseWrinkles = featureExtracter.findWrinkles(shortImage, featureExtracter.getOnNose()); dataModel.betweenEyesWrinkles = featureExtracter.findWrinkles(shortImage, featureExtracter.getBetweenEyes()); dataModel.Label = Path.GetFileName(Path.GetDirectoryName(file)); emotionList.Add(dataModel); } index++; } return(emotionList); } }