矩形不在检测到的眼睛对周围

Rectangle not around detected eye pair

本文关键字:眼睛 周围 检测      更新时间:2023-10-16

我正在使用opencv 2.4.2和c ++。我对检测眼睛对的矩形有一个小问题。矩形不会出现在眼对周围,而是出现在检测到的面部矩形之外。我想我可能没有正确获得正确的参数。

这是一段代码

for(int i=0;i<faces.size();i++){
        rectangle(frame,faces[i],Scalar(255,0,0),1,8,0);
        Mat face  = frame(faces[i]);
        cvtColor(face,face,CV_BGR2GRAY);
        imwrite("C:/Users/DELL/Documents/Visual Studio 2010/Projects/Haarcascade/Haarcascade/fot.jpg",face);
        vector<Rect> eyes;
        eye.detectMultiScale(face,eyes);
        for( size_t j = 0; j < eyes.size(); j++ ){
            rectangle(frame,eyes[i],Scalar(255,0,0),4,8,0);
        }
}

谁能帮忙?谢谢

您正在寻找从0face->width和从0face->height范围内的眼睛,因此您可以获得相对于面部边界的眼睛坐标,然后在原始帧上绘制眼睛。您需要在框架中添加面部坐标,如下所示:

Rect r(faces[i].x + eyes[i].x, faces[i].y + eyes[i].y, eyes[i].width,eyes[i].height );
rectangle(frame,r,Scalar(255,0,0),4,8,0);