【问题标题】:How can I resize an image where the face should be cropped and scaled to fit the size?如何调整应裁剪和缩放面部以适合大小的图像大小?
【发布时间】:2015-07-16 13:53:03
【问题描述】:

我的网络摄像头拍摄图像。但是 opencv 性别分类需要图像与用于训练的图像大小相同。所以我需要我的网络摄像头图像为 300x300,其中网络摄像头图像中的人脸适合 300x300 的分辨率。
我已经使用 opencv 人脸级联分类器识别了网络摄像头图像中的人脸。
但是我怎样才能裁剪那张脸以适应 300x300 的大小呢?
由于我是opencv的新手,请帮助一些代码行。

【问题讨论】:

标签: c++ opencv image-processing cascade-classifier


【解决方案1】:

这里有一个小样本,可以帮助您裁剪和调整您的面孔

#include <opencv2\opencv.hpp>
using namespace cv;

int main()
{
     Mat3b img = imread("path_to_image");

    // You find the rectFace through face detection
    // Here the values are hardcoded
    Rect rectFace(235, 30, 45, 55);

    Mat3b detection = img.clone();
    rectangle(detection, rectFace, Scalar(0,255,0));

    // Crop the image
    Mat3b face(img(rectFace)); 

    // Resize the face to 300x300
    Mat3b resized;
    resize(face, resized, Size(300,300), 0.0, 0.0, INTER_LANCZOS4);

    // Apply gender classification on resized

    imshow("Detection", detection);
    imshow("Face", face);
    imshow("Resized", resized);
    waitKey();

    return 0;
}

检测到的人脸:

裁剪的脸:

调整大小的脸:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多