Ask Your Question

Revision history [back]

Hi, I'm not sure you can do it in a single step with OpenCV. I would decompose the problem in two steps : create a learning database of the person you want to tag, and the recognition step. For the first step, you will first have to create a database containing multiple view of the face of each person you want to recognize. That database will consist of a list of pictures with the corresponding name. So to sum up:

vector<Mat> images;
vector<int> labels;
vector<string> names;
images = [pic1;pic2;pic3;pic4;...]
labels = [0   ;0   ;1   ;2   ;...]
names  = [nom1;nom2;nom3]

In this example, you have 3 persons, with some pictures of them. labels correspond to the index in the names vector.

You can then use a classifier (I suggest you the LBP face detector):

Ptr<FaceRecognizer> model =  createLBPHFaceRecognizer();
model->train(images, labels);

Now model contains everything you need to tag peoples. To get the class, you just have to do that:

int predicted = model->predict(askingImg);
cout<<"Hello "<<names[predicted]<<"!"<<endl;

Hi, I'm not sure you can do it in a single step with OpenCV. I would decompose the problem in two steps : create a learning database of the person you want to tag, and the recognition step. For the first step, you will first have to create a database containing multiple view of the face of each person you want to recognize. That database will consist of a list of pictures with the corresponding name. So to sum up:

vector<Mat> images;
vector<int> labels;
vector<string> names;
images = [pic1;pic2;pic3;pic4;...]
labels = [0   ;0   ;1   ;2   ;...]
names  = [nom1;nom2;nom3]

In this example, you have 3 persons, with some pictures of them. labels correspond to the index in the names vector.

You can then use a classifier (I suggest you the LBP face detector):

Ptr<FaceRecognizer> model =  createLBPHFaceRecognizer();
model->train(images, labels);

Now model contains everything you need to tag peoples. To get the class, you just have to do that:

int predicted = model->predict(askingImg);
cout<<"Hello "<<names[predicted]<<"!"<<endl;