C# Emgu CV Trouble Predicting Face EigenFaceRecognizer

Viewed 574

I'm trying to save face images and predict them using Emgu CV 4.4 with EigenFaceRecognizer using .Net5.

Basically I am getting a single image, resizing it (I read somewhere that smaller images have better accuracy),
adding it to the List<Mat>and saving the trained data to see what is there out of curiosity.

After that I'm using the same image and attempt to predict what it is (label).

Unfortunately it fails producing this error.
Emgu.CV.Util.CvException: 'OpenCV: Wrong shapes for given matrices. Was size(src) = (1,57600), size(W) = (19200,1).'

I also tried imageForTraining.Mat within Predict however the same error occurred.

// Get The GrayImage And Resize It.
Image<Bgr, byte> imageForTraining = grayImage.Resize(128, 150, Emgu.CV.CvEnum.Inter.Cubic);
                    
// Create New cv::Mat Lists.
List<Mat> mats = new List<Mat>()
{
    imageForTraining.Mat
};
                    
// Dirty Solution For Label Testing.
List<int> labels = new List<int>()
{
    0
};

// Create Face Recognizer And Tell It There Is Only 1 Item.
FaceRecognizer faceRecognizer = new EigenFaceRecognizer(1);

// Write Data To File To See If Something Is There.
faceRecognizer.Write("trainingData");

// Attempt To Train.
faceRecognizer.Train(new VectorOfMat(mats.ToArray()), new VectorOfInt(labels.ToArray()));

// Test Image That Was Just Trained.
FaceRecognizer.PredictionResult predictionResult = faceRecognizer.Predict(imageForTraining);
0 Answers
Related