string cascadeName = "haarcascade_frontalface_alt.xml";
	string nestedCascadeName = "haarcascade_eye_tree_eyeglasses.xml";
	scale = 1.3;
	if (!nestedCascade.load(samples::findFileOrKeep(nestedCascadeName)))
	{
		cerr << "Could not load classifier cascade" << endl;
		return 1;
	}

	if (!cascade.load(samples::findFile(cascadeName)))
	{
		cerr << "Could not load classifier cascade" << endl;
		return 1;
	}

	double scale = 1.3;
	string inputName = inputName = "image.jpg";
	bool tryflip = false;

	Mat image = imread(samples::findFileOrKeep(inputName), IMREAD_COLOR);
	if (image.empty())
	{
		if (!capture.open(samples::findFileOrKeep(inputName)))
		{
			cout << "Could not read " << inputName << endl;
			return 1;
		}
	}

	cout << "Detecting face(s) in " << inputName << endl;
	if (!image.empty())
	{
		detectAndDraw(image, cascade, nestedCascade, scale, tryflip);
		waitKey(0);
	}

void detectAndDraw(Mat& img, CascadeClassifier& cascade,
	CascadeClassifier& nestedCascade,
	double scale, bool tryflip)
{
	double t = 0;
	vector<Rect> faces, faces2;
	const static Scalar colors[] =
	{
		Scalar(255,0,0),
		Scalar(255,128,0),
		Scalar(255,255,0),
		Scalar(0,255,0),
		Scalar(0,128,255),
		Scalar(0,255,255),
		Scalar(0,0,255),
		Scalar(255,0,255)
	};
	Mat gray, smallImg;

	cvtColor(img, gray, COLOR_BGR2GRAY);
	double fx = 1 / scale;
	resize(gray, smallImg, Size(), fx, fx, INTER_LINEAR_EXACT);
	equalizeHist(smallImg, smallImg);

	t = (double)getTickCount();
	cascade.detectMultiScale(smallImg, faces,
		1.1, 2, 0
		//|CASCADE_FIND_BIGGEST_OBJECT
		//|CASCADE_DO_ROUGH_SEARCH
		| CASCADE_SCALE_IMAGE,
		Size(30, 30));
	t = (double)getTickCount() - t;
	printf("detection time = %g ms\n", t * 1000 / getTickFrequency());
	
	for (size_t i = 0; i < faces.size(); i++)
	{
		Rect r = faces[i];
		Mat smallImgROI;
		vector<Rect> nestedObjects;
		Point center;
		Scalar color = colors[i % 8];
		int radius;

		rectangle(img, Point(cvRound(r.x*scale), cvRound(r.y*scale)),
			Point(cvRound((r.x + r.width - 1)*scale), 
cvRound((r.y + r.height - 1)*scale)),
			color, 2, 8, 0);
	
		if (nestedCascade.empty())
			continue;
		
		smallImgROI = smallImg(r);
		nestedCascade.detectMultiScale(smallImgROI, nestedObjects,
			1.1, 2, 0
			//|CASCADE_FIND_BIGGEST_OBJECT
			//|CASCADE_DO_ROUGH_SEARCH
			//|CASCADE_DO_CANNY_PRUNING
			| CASCADE_SCALE_IMAGE,
			Size(30, 30));

		for (size_t j = 0; j < nestedObjects.size(); j++)
		{
			Rect nr = nestedObjects[j];
			center.x = cvRound((r.x + nr.x + nr.width*0.5)*scale);
			center.y = cvRound((r.y + nr.y + nr.height*0.5)*scale);
			radius = cvRound((nr.width + nr.height)*0.25*scale);
			circle(img, center, radius, color, 2, 8, 0);
		}
	}
	
	imshow("result", img);
}

Ptr<EigenFaceRecognizer> model = EigenFaceRecognizer::create();
	for (int i = 0; i < nlabels; i++)
		model->setLabelInfo(i, labelsInfo[i]);
	model->train(images, labels);
	string saveModelPath = "face-rec-model.txt";
	cout << "Saving the trained model to " << saveModelPath << endl;
	model->save(saveModelPath);

	Mat testSample = imread(argv[3], 0);
	int predictedLabel = model->predict(testSample);
	string result_message = 
format("Predicted class = %d / Actual class = %d.", 
predictedLabel, testLabel);
	cout << result_message << endl;

	auto it = labelsInfo.find(predictedLabel);
	string name;
	if (it != labelsInfo.end())
	{
		name = it->second;
		cout << "Name is : " << name << endl;
	}