简体   繁体   中英

Use Emgucv to do face recognition, show no predict result

I'm using Emgucv to do face recognition, but the Predict method of FaceRecognizer doesn't work. Every time when I ran these codes below, I got no result. Does any one know how to fix it? Thanks in advance. The Emgucv version is Emgu.CV-3.0.0-rc1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

using Emgu.CV.UI;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;

namespace ConsoleFaceRecognition
{
class Program
{
    static void Main(string[] args)
    {
        //training variables             
        Image<Bgr, Byte>[] images = new Image<Bgr, Byte>[20];
        int[] labels = new int[20];


        for (int i = 0; i < 10; i++)
        {
            images[i] = new Image<Bgr, Byte>("D:/visual studio 2013 projects/ConsoleFaceRecognition/ConsoleFaceRecognition/trainingImages/s1/11" + i.ToString() + ".png");
            images[i + 10] = new Image<Bgr, Byte>("D:/visual studio 2013 projects/ConsoleFaceRecognition/ConsoleFaceRecognition/trainingImages/s2/21" + i.ToString() + ".png");
            labels[i] = 1;
            labels[i + 10] = 2;
        }

        FaceRecognizer recognizer = new FisherFaceRecognizer(0, 3500);
        recognizer.Train(images, labels);

        Image<Bgr, Byte> testImage = new Image<Bgr, Byte>("D:/visual studio 2013 projects/ConsoleFaceRecognition/ConsoleFaceRecognition/trainingImages/s2/213.png");
        FaceRecognizer.PredictionResult result = recognizer.Predict(testImage);


        Console.Write(result.Label);
    }
}
}

I don't think 20 images is enough for training, increase the number of samples if possible. Also size and content of your samples matter. All faces in those images should have the same size and be for example frontal for your training to work.

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM