Opencv learning notes () -- Overview facerecognizer contrib

Source: Internet
Author: User

In the latest version of 2.4.2, the document update is also a highlight. refrence manual has expanded more than 200 pages and added the contrib part of the document. Contrib refers to the newly added modules in opencv, but it is not very stable and can be considered as a prototype. This time, in conjunction with the refman reading, we will introduce the facerecognizer face recognition class, which is also highlighted in the 2.4.2 Update log, and the supporting documents are quite enriched. The base class of this class is also the algorithm class. For a brief introduction to the algorithm class, see my previous blogopencv Study Notes (50) -- algorithm class introduction (core ), the interface functions in this class are also extremely simple. The task of face recognition is two parts. Training and prediction correspond to the train function and predict function, respectively, there are also corresponding data loading and saving functions save and load. However, it can also call its base class Algorithm functions. It is particularly noted that the predicted parameters in face recognition can also be adjusted, but only the train and predict functions are provided here. Why is there no setparameter function, the reason is that the parameters of face recognition methods are different. You need to adjust the parameters in real time through the get and set functions of algorithm ~~ V5!

Let's talk about the training process. The two parameters of the train function are also very simple. The training Image Group vector <mat> and the corresponding label group vector <int>, the label Label only needs to ensure that the labels of the same person are the same. It is convenient to input images in the order of tags. Prediction can be called in two ways. The parameters include the test image, the returned tag value, and the similarity between the test sample and the tag sample. The returned tag value is-1, indicating that the test sample has no correspondence or distance in the training set. Here we use fisherface as an example to illustrate how to train and predict:

vector<Mat> images;vector<int> labels;// images for first personimages.push_back(imread("person0/0.jpg", CV_LOAD_IMAGE_GRAYSCALE));labels.push_back(0);images.push_back(imread("person0/1.jpg", CV_LOAD_IMAGE_GRAYSCALE));labels.push_back(0);// images for second personimages.push_back(imread("person1/0.jpg", CV_LOAD_IMAGE_GRAYSCALE));labels.push_back(1);images.push_back(imread("person1/1.jpg", CV_LOAD_IMAGE_GRAYSCALE));labels.push_back(1);Ptr<FaceRecognizer> model = createFisherFaceRecognizer();model->train(images, labels);Mat img = imread("person1/2.jpg", CV_LOAD_IMAGE_GRAYSCALE);int predicted = model->predict(img);

Of course, we do not need to perform a training every time we use it. We can save the trained model as a file through the Save function, and we only need to load it the next time we use it.

Currently, three face recognition solutions are supported: feature face eigenface, Fisher face fisherface, and lbphface. Call the createeigenfacerecognizer, createfisherfacerecognizer, and createlbphfacerecognizer functions to create models.

For eigenface, the dimensions of PCA Principal Component num_components and the threshold value threshold during prediction, principal component does not have a selection criterion, which depends on the size of input data, generally, the 80-dimension principal component is considered sufficient. In addition to these two input parameters, eigenvalues and eigenvectors represent feature values and feature vectors respectively. The mean parameter is the average value of the training sample, projections is the predicted value of the training data, and labels is the threshold value of the prediction.

For fisherface, It is very similar to eigenface. There are also num_components and threshold parameters and the other five parameters. The Dimension Reduction of fisherface is obtained by LDA. The default value is C-1. If the initial value is not in the range of (0, C-1], it is automatically set to c-1.

In particular, the training and test images of eigenface and fisherface must both be grayscale and normalized.

For lbphface, I don't want to introduce it too much. The simple and effective mechanism of lbphface is everyone's favorite. parameters include radius, the size of the neighborhood, that is, the number of sampling points neighbors, the number of cells in the X and Y directions is grid_x and grid_y. There are two parameters histograms for the histogram obtained from the training data, and labels for the label corresponding to the histogram. This method also requires that the training and testing images are grayscale images.

Next, we should further study this face recognition class in combination with the document. A large number of my previous face experiments were carried out under MATLAB. With this powerful tool, I feel that more and more students will choose to use opencv instead of Matlab as projects set by teachers and bosses. Hope we all love opencv better and better. Welcome

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.