#include <iostream>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <fstream>
#include <stdlib.h>
#include <opencv2/opencv.hpp>
#include <locale>
#include <string>
#include <vector>
#define MY_SIZE Size(90, 90)
using namespace cv;
using namespace std;
CascadeClassifier faceCascade;
int main()
{
int c=0;
if (!faceCascade.load("./haarcascade_frontalface_alt.xml"))
{
cout << "导入haarcascade_frontalface_alt.xml时出错 !" << endl;
return 0;
}
VideoCapture cap(1);
Mat img, imgGray;
vector < Rect > faces;
if (!cap.isOpened())
{
return 1;
}
while (c != 27)
{
cap >> img;
if (img.channels() == 3)
{
cvtColor(img, imgGray, CV_RGB2GRAY);
}
else
{
imgGray = img;
}
faceCascade.detectMultiScale(imgGray, faces, 1.3, 6, 0, Size(20, 20));
if (faces.size() > 0)
{
for (int i = 0; i < faces.size(); i++)
{
rectangle(imgGray, Point(faces[i].x, faces[i].y),Point(faces[i].x + faces[i].width,faces[i].y + faces[i].height),Scalar(0, 255, 0), 1, 8);
Mat faceROI;
int count = 0;
faceROI = imgGray(faces[i]);
resize(faceROI, faceROI, MY_SIZE);
imwrite("jt.jpg", faceROI);
}
}
}
return 0;
}
arm-linux-gnueabihf-g++ -o video1 video.cpp `pkg-config --cflags --libs opencv`