19,468
社区成员
发帖
与我相关
我的任务
分享
using namespace cv;
using namespace std;
string face_cascade_name = "haarcascade_frontalface_alt.xml";
CascadeClassifier face_cascade;
string window_name = "人脸识别";
void detectAndDisplay(Mat frame){
std::vector<Rect> faces;
Mat frame_gray;
cvtColor(frame, frame_gray, CV_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(40, 40));
for (int i = 0; i < faces.size(); i++){
Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
Point pt2(faces[i].x, faces[i].y);
rectangle(frame, pt1, pt2, cvScalar(255, 0, 0, 0), 3, 8, 0);
}
imshow(window_name, frame);
}
int main(int argc, char* argv[])
{
VideoCapture cap(0);
if (!cap.isOpened())
return -1;
Mat edges;
if (!face_cascade.load(face_cascade_name)){ //( !eyes_cascade.load(eyes_cascade_name)){
printf("无法加载级联分类器文件!\n");
return -1;
}
int nTick = 0;
for (;;)
{
if (!cap.isOpened())
{
continue;
}
Mat frame;
nTick = getTickCount();
cap >> frame; // get a new frame from camera
if (frame.data == NULL)
{
continue;
}
cvtColor(frame, edges, CV_BGR2BGRA);
detectAndDisplay(edges);
if (waitKey(30) >= 0) break;
}
return 0;
}
你好,我的程序是这样的,请问要加在哪里呢?