Search code examples
opencvemgucvface-recognition

Emgucv cannot train more than 210 images using EigenFaceRecognizer it stop writing new details or data


Good day everyone I am relatively new to OpenCV using .net wrapper Emgucv my program is simple face detection and recognition, first I train user faces, at least 20 images of 100x100pixel per user and write (EigenFaceRecognizer) the data to yml files, then load this files(user images and data in yml) before running real time recognition or comparing, it worked perfectly fine with 9 user (9x20 = 180 images). However when i try to register or train another user I notice the (EigenFaceRecognizer) stop writing the data in yml. How do we solve this? The format of my data with yml extension below

 opencv_eigenfaces:
   threshold: .Inf
   num_components: 10
   mean: !!opencv-matrix
   rows: 1
   cols: 4096
   dt: d
   data: []    

The trainingData.yml https://www.dropbox.com/s/itm58o24lka9wa3/trainingData.yml?dl=0


Solution

  • I figure it out the problem is just not enough time in writing the data so I need to increase the delay.

     private async Task LoadData()
        {
            outputBox.Clear();
            var i = 0;
            var itemData = Directory.EnumerateFiles("trainingset/", "*.bmp");
            var enumerable = itemData as IList<string> ?? itemData.ToList();
            var total = enumerable.Count();
            _arrayNumber = new int[total];
            var listMat = new List<Mat>();
    
            foreach (var file in enumerable)
            {
                var inputImg = Image.FromFile(file);
                _inputEmGuImage = new Image<Bgr, byte>(new Bitmap(inputImg));
                var imgGray = _inputEmGuImage.Convert<Gray, byte>();
                listMat.Add(imgGray.Mat);
                var number = file.Split('/')[1].ToString().Split('_')[0];
                if (number != "")
                {
                    _arrayNumber[i] = int.Parse(number);
                }
                i++;
                processImg.Image = _inputEmGuImage.ToBitmap();
                outputBox.AppendText($"Person Id: {number} {Environment.NewLine}");
                if (total == i)
                {
                    fisherFaceRecognizer.Train(listMat.ToArray(), _arrayNumber);
                    fisherFaceRecognizer.Write(YlmPath);
                   // FaceRecognition.Train(listMat.ToArray(), _arrayNumber);
                   // FaceRecognition.Write(YlmPath);
                    MessageBox.Show(@"Total of " + _arrayNumber.Length + @" successfully loaded");
                }
                await Task.Delay(10);
            }
        }