3

我正在使用 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);

        }

}

有人可以帮忙吗?谢谢

4

1 回答 1

1

You are looking for eyes in range from 0 to face->width and from 0 to face->height, so you get eyes coordinates relatively to face boundaries, and then you draw eyes on original frame. You need to add coordinates of face in frame, something like that :

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);
于 2014-03-03T09:02:05.270 回答