首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Roi用于检测眼睛区域

Roi用于检测眼睛区域
EN

Stack Overflow用户
提问于 2015-11-16 23:45:51
回答 2查看 520关注 0票数 0

我希望将ROI分配给检测到的人脸,以便只裁剪眼睛区域。

我试过这个:

代码语言:javascript
复制
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 4, CASCADE_SCALE_IMAGE, Size(20, 20));

size_t i = 0; // ic is index of current element

for (i = 0; i < faces.size(); i++) // Iterate through all current elements (detected faces)

{

    Point pt1(faces[i].x, faces[i].y); // Display detected faces on main window - live stream from camera
    Point pt2((faces[i].x + faces[i].height), (faces[i].y + faces[i].width));
    rectangle(frame, pt1, pt2, Scalar(0, 255, 0), 2, 8, 0);

    // set ROI for the eyes

    Rect Roi = faces[i];

    Roi.height = Roi.height / 4;

    Roi.y = Roi.y + Roi.height;

    cv::Mat crop = frame(Roi);

    imshow("ROI", crop);

这是输出:ROI

如何才能使此输出更准确,如下面的图像Only eyes Roi

EN

回答 2

Stack Overflow用户

发布于 2015-11-17 07:25:00

您可以使用下面的函数以给定的百分比值缩小Rect

代码语言:javascript
复制
Rect shrinkRect( Rect rect, int percent )
{
        if (percent>99)
        return rect;

    Rect newrect;
    newrect.width=( rect.width * percent ) / 100;
    newrect.height=( rect.height * percent ) / 100;
    newrect.x = rect.x + ( rect.width - newrect.width ) / 2;
    newrect.y = rect.y + ( rect.height - newrect.height ) / 2;

    return newrect;
}

测试代码:

代码语言:javascript
复制
#include "opencv2/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

Rect shrinkRect( Rect rect, int percent )
{
    if (percent>99)
        return rect;

    Rect newrect;
    newrect.width=( rect.width * percent ) / 100;
    newrect.height=( rect.height * percent ) / 100;
    newrect.x = rect.x + ( rect.width - newrect.width ) / 2;
    newrect.y = rect.y + ( rect.height - newrect.height ) / 2;

    return newrect;
}

int main( void )
{

    Rect r;
    r.x = 100;
    r.y = 100;
    r.width = 200;
    r.height = 200;

    cout << r  << endl;
    cout << shrinkRect( r, 75 ) << endl;
    cout << shrinkRect( r, 50 ) << endl;
    cout << shrinkRect( r, 30 ) << endl;

    return 0;
}

测试代码输出:

代码语言:javascript
复制
[200 x 200 from (100, 100)]
[150 x 150 from (125, 125)]
[100 x 100 from (150, 150)]
[60 x 60 from (170, 170)]
票数 0
EN

Stack Overflow用户

发布于 2015-11-17 17:34:19

您可能希望使用眼睛分类器来获取唯一的眼睛区域。

有单独的(左/右)眼睛分类器和眼睛对分类器(例如haarcascade_mcs_eyepair_big.xml)

这些应该会给你的眼睛带来ROI。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33739263

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档