04 FaceRecognizer train load

sample35_ FaceRecognizer_Train_load
#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() {

<%%KEEPWHITESPACE%%>    vector&lt;Mat&gt; images;
<%%KEEPWHITESPACE%%>    vector&lt;int&gt; labels;
<%%KEEPWHITESPACE%%>    /*
<%%KEEPWHITESPACE%%>    // images for first person
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s1/1.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(0);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s1/2.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(0);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s1/3.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(0);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s1/4.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(0);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s1/5.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(0);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s1/6.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(0);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s1/7.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(0);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s1/8.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(0);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s1/9.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(0);
<%%KEEPWHITESPACE%%>    //images.push_back(imread("/Users/powenko/Desktop/face/s1/9.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    //labels.push_back(0);
<%%KEEPWHITESPACE%%>    // images for second person
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s2/1.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(1);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s2/2.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(1);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s2/3.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(1);
<%%KEEPWHITESPACE%%>    images.push_back(imread("/Users/powenko/Desktop/face/s2/4.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>    labels.push_back(1);
<%%KEEPWHITESPACE%%>   // images.push_back(imread("/Users/powenko/Desktop/face/s2/5.jpg", CV_LOAD_IMAGE_GRAYSCALE));
<%%KEEPWHITESPACE%%>   // labels.push_back(1);
<%%KEEPWHITESPACE%%>    */
<%%KEEPWHITESPACE%%>    Ptr&lt;FaceRecognizer&gt; model = createFisherFaceRecognizer();

<%%KEEPWHITESPACE%%>    //model-&gt;train(images, labels);
<%%KEEPWHITESPACE%%>    model-&gt;load("/Users/powenko/Desktop/face.xml");

<%%KEEPWHITESPACE%%>    Mat img = imread("/Users/powenko/Desktop/face/s2/5.jpg", CV_LOAD_IMAGE_GRAYSCALE);
<%%KEEPWHITESPACE%%>    int predicted = model-&gt;predict(img);

<%%KEEPWHITESPACE%%>    return 0;
}

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