在OpenCV中限制Mat图像

时间:2015-09-22 14:53:43

标签: opencv image-processing image-recognition mat opencv3.0

我在OpenCV中引入。我试图从脸部(眼睛和嘴巴)识别出几个部位。我的软件能正确识别脸部和眼睛,但嘴巴有些问题。它向我展示了几张从脸部到顶部的嘴巴,我意识到在脸部的下方显示了嘴巴,我需要从脸部限制图像,只能用嘴巴。

我接下来的代码:

Mat faceRoi = frame_gray(faces[i]);

    vector<Rect> eyes;
    eyes_cascade.detectMultiScale(faceRoi, eyes);

    cout << "NUMERO EYES: " << eyes.size() << endl;

    for(unsigned int j=0; j<eyes.size(); j++)
    {
        Point center( faces[i].x + eyes[j].x + eyes[j].width * 0.5, faces[i].y + eyes[j].y + eyes[j].height * 0.5);
        int radius = cvRound( (eyes[j].width + eyes[j].height) * 0.3 );
        circle(frame, center, radius, Scalar( 255, 0, 0 ), 3, 8, 0 );       
    }

    cout << " FACE-ROI ---->    ROWS: " << faceRoi.rows << "  COLS: " << faceRoi.cols << endl;

    vector<Rect> smiles;

    smile_cascade.detectMultiScale(smileRoi, smiles);
    cout << "NUMERO SMILES: " << smiles.size() << endl; 
    for(unsigned int k=0; k<smiles.size(); k++)
    {
        Point center(faces[i].x + smiles[k].x + smiles[k].width * 0.5, faces[i].y + smiles[k].y + smiles[k].height * 0.5);
        ellipse(frame, center, Size(smiles[k].width * 0.5, smiles[k].height * 0.5), 0, 0, 360, Scalar(0,255,255), 3, 8, 0);
    }    

我的问题是下一个...我怎么能用新的限制复制另一个图像(范围,我只想要那个图像的中间或2/3部分,从嘴里的位置)。< / p>

希望有人能帮助我! 谢谢!

1 个答案:

答案 0 :(得分:0)

你可以像下面的代码一样定义smallRoi(参考:smiledetect.cpp

vector<Rect> smiles;

// insert this lines to your code    
Rect r = faces[i];
const int half_height=cvRound((float)r.height/2);
r.y=r.y + half_height;
r.height = half_height-1;
smileRoi = frame_gray( r );

smile_cascade.detectMultiScale(smileRoi, smiles);