功能1:人脸检测,效果不好,基本上一般判断错误。



//功能:人脸检测,效果不好,基本上一般判断错误。


#include <opencv2\opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

string xmlPath = "E:\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_default.xml";

int main()
{
	Mat img = imread("2.jpg");
	imshow("input image",img);

	CascadeClassifier detector;
	bool bstatue = detector.load(xmlPath);
	if (!bstatue)
	{
		cout<<"load xml文件失败"<<endl;
		return -1;
	}

	vector<Rect>faces;
	detector.detectMultiScale(img,faces,1.1,3,0,Size(30,30));
	for (size_t t = 0; t < faces.size(); t++)
	{
		rectangle(img,faces[t],Scalar(0,0,255),2,8);
	}
	imshow("Result",img);
	waitKey(0);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/u011473714/article/details/88226134