在c ++中使用OpenCV进行图像中的人脸检测问题 [英] Problems with face detection in images using OpenCV in c++

查看:80
本文介绍了在c ++中使用OpenCV进行图像中的人脸检测问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在网络摄像头中编写了这个用于人脸检测的代码,它对我来说非常适合。所以,我想我修改代码并将其用于静态图像来检测图像中的面部。

但不幸的是它不适合我。所以,任何人都可以纠正我的错误。这是我的代码。



CascadeClassifier face_cascade;

face_cascade.load(C:/ opencv / sources / data / haarcascades / haarcascade_frontalface_alt。 xml);

if(!face_cascade.load(C:/opencv/sources/data/haarcascades/haarcascade_frontalface_alt.xml))



{

返回1;

}



namedWindow(outputimage,1); < br $>


asp = imread(leena.JPG);



std :: vector< rect>面孔;



face_cascade.detectMultiScale(asp,faces,1.1,5,CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_SCALE_IMAGE,大小(30,30));





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);



矩形(asp,pt1,pt2,cvScalar(0,255,0,0),1,0,0);

}



imshow(outputimage,asp);

So, I wrote this code for face detection in webcam and it works perfectly for me.So, i thought how about i modify the code and use it for static images to detect faces in the image.
But unfortunately its not working for me. So, can anyone correct my mistake. Here is my code.

CascadeClassifier face_cascade;
face_cascade.load("C:/opencv/sources/data/haarcascades/haarcascade_frontalface_alt.xml");
if(!face_cascade.load("C:/opencv/sources/data/haarcascades/haarcascade_frontalface_alt.xml"))

{
return 1;
}

namedWindow("outputimage",1);

asp = imread("leena.JPG");

std::vector<rect> faces;

face_cascade.detectMultiScale(asp,faces,1.1,5,CV_HAAR_FIND_BIGGEST_OBJECT|CV_HAAR_SCALE_IMAGE,Size(30,30));


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(asp,pt1,pt2,cvScalar(0,255,0,0),1,0,0);
}

imshow("outputimage",asp);

推荐答案

这篇关于在c ++中使用OpenCV进行图像中的人脸检测问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆