Esempio n. 1
0
void FaceDetection::start_work(const cv::Mat &image)
{
	in_image = image.clone();
	out_image = image.clone();
	cv::cvtColor(in_image, in_image, cv::COLOR_BGR2GRAY);	// 转为灰度图
	cv::equalizeHist(in_image, in_image);	// 直方图均衡化
	faces.clear();
	cascade_classifier.detectMultiScale(in_image, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
	if (!faces.empty())
	{
		for (int i = 0; i != faces.size(); ++i)
			cv::rectangle(out_image, faces[i], cv::Scalar(0, 0, 255), 1, 8, 0);	//	画出人脸部分的矩形框
		if (save)
		{
			faces[0].y -= static_cast<int>(0.1 * faces[0].height);
			faces[0].height += static_cast<int>(0.1 * faces[0].height);
			cv::resize(in_image(faces[0]), in_image, cv::Size(92, 112));	// 可自己定义图片大小
			save_faces(in_image);
			system("cls");
			std::cout << "OK,您已经保存了" << photo_numbers << "张图片了" << std::endl;
			save = false;
		}
		if (recognize)
		{
			faces[0].y -= static_cast<int>(0.1 * faces[0].height);
			faces[0].height += static_cast<int>(0.1 * faces[0].height);
			cv::resize(in_image(faces[0]), in_image, cv::Size(92, 112));
			cv::imwrite(".\\data\\me.pgm", in_image);
			set_have_image(true);
		}
	}
	cv::imshow("当前帧", out_image);
}
Esempio n. 2
0
qsave_faces()
{
char *title;

if ((title = get_filename("save faces", 
	".FAC")) != NULL)
	{
	save_faces(title);
	}
}