当我播放人脸检测代码时,我感到有些困惑。当我评论这两句话时:
//cvtColor( frame, frame_gray, CV_BGR2GRAY );
//equalizeHist( frame_gray, frame_gray );
结果还是一样,这意味着Opencv(detectMultiScale)仍然可以成功找到人脸。我在想将彩色图像更改为灰度图像,然后得到灰度图像的直方图有什么意义?
我附上部分代码如下:
while (cvWaitKey(10) < 0)
{
Mat frame = cvQueryFrame( capture ); // get the next frame of video
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(30, 30) ); // Detect faces
for( int i = 0; i < faces.size(); i++ ) // for each face found
{
Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 ); // location of this face
ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 ); // draw ellipse around this face}
imshow( "faces", frame);
}
/////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
或者:
while (cvWaitKey(10) < 0)
{
Mat frame = cvQueryFrame( capture ); // get the next frame of video
//cvtColor( frame, frame_gray, CV_BGR2GRAY );
//equalizeHist( frame_gray, frame_gray );
face_cascade.detectMultiScale( frame, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) ); // Detect faces
for( int i = 0; i < faces.size(); i++ ) // for each face found
{
Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 ); // location of this face
ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 ); // draw ellipse around this face}
imshow( "faces", frame);
}
//////////////////////////////////////////////