02 FaceRecognizer train

#include <iostream>
#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv2/objdetect/objdetect.hpp>

#include <opencv2/contrib/contrib.hpp>
#include <opencv2/opencv.hpp>


using namespace cv ;
using namespace std ;


int main() {
   
    vector<Mat> images;
    vector<int> labels;
    // images for first person
    images.push_back(imread("/Users/powenko/Desktop/face/s1/1.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(0);
    images.push_back(imread("/Users/powenko/Desktop/face/s1/2.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(0);
    images.push_back(imread("/Users/powenko/Desktop/face/s1/3.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(0);
    images.push_back(imread("/Users/powenko/Desktop/face/s1/4.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(0);
    images.push_back(imread("/Users/powenko/Desktop/face/s1/5.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(0);
    images.push_back(imread("/Users/powenko/Desktop/face/s1/6.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(0);
    images.push_back(imread("/Users/powenko/Desktop/face/s1/7.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(0);
    images.push_back(imread("/Users/powenko/Desktop/face/s1/8.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(0);
    images.push_back(imread("/Users/powenko/Desktop/face/s1/9.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(0);
    //images.push_back(imread("/Users/powenko/Desktop/face/s1/9.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    //labels.push_back(0);
    // images for second person
    images.push_back(imread("/Users/powenko/Desktop/face/s2/1.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(1);
    images.push_back(imread("/Users/powenko/Desktop/face/s2/2.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(1);
    images.push_back(imread("/Users/powenko/Desktop/face/s2/3.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(1);
    images.push_back(imread("/Users/powenko/Desktop/face/s2/4.jpg", CV_LOAD_IMAGE_GRAYSCALE));
    labels.push_back(1);
   // images.push_back(imread("/Users/powenko/Desktop/face/s2/5.jpg", CV_LOAD_IMAGE_GRAYSCALE));
   // labels.push_back(1);
    
    Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
    
    model->train(images, labels);
    
    
    Mat img = imread("/Users/powenko/Desktop/face/s2/5.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    int predicted = model->predict(img);
    
    
    
    
    return 0;
}

screen-shot-2016-12-03-at-12-50-39-am

screen-shot-2016-12-03-at-12-50-50-am

OpenCV
CH01 簡介CH02 OpenCV APICH03 繪圖CH04 應用範例CH06 haarcascadesCH06 surf和siftCH07 OCRCH09 FaceCH5 輪廓(findContours、drawContours)