gpt4 book ai didi

c++ - 如何调整应裁剪和缩放面部以适合大小的图像大小?

转载 作者:行者123 更新时间:2023-11-28 06:10:19 29 4
gpt4 key购买 nike

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

最佳答案

这里有一个小示例,可以帮助您裁剪和调整面部的大小:

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

检测到的人脸:

enter image description here

裁剪脸:

enter image description here

调整后的脸:

enter image description here

关于c++ - 如何调整应裁剪和缩放面部以适合大小的图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31397902/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com