如何调整图像的面积应裁剪和缩放到适合的大小? [英] How can I resize an image where the face should be cropped and scaled to fit the size?

查看:712
本文介绍了如何调整图像的面积应裁剪和缩放到适合的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络摄像头拍摄图像。但是opencv性别分类需要的图像与用于训练的图像的大小相同。所以我需要我的网络摄像头图像是300x300,其中网络摄像头图像中的脸适合分辨率300x300。

我使用opencv面部级联分类器在网络摄像头图像中识别了脸。

但是如何裁剪该面部以适应300x300的大小?

请帮助一些代码行,因为我是opencv的新人。

My webcam takes images. But opencv gender classification needs the images to be of the same size of that of the images used to train. So I need my webcam images to be 300x300 where the face in the webcam images would fit the resolution 300x300.
I have identified the face in the webcam image using opencv face cascade classifiers.
But how can I crop that face to fit in the size of 300x300?
Please help with some code lines as I am new to opencv.

推荐答案

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

Here a small sample that will help you to crop and resize your faces:

#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;
}

检测到的脸:

剪裁脸:

>

调整大小的脸孔:

这篇关于如何调整图像的面积应裁剪和缩放到适合的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆