c++ - How can I resize an image where the face should be cropped and scaled to fit the size? -
my webcam takes images. opencv gender classification needs images of same size of of images used train. need webcam images 300x300 face in webcam images fit resolution 300x300.
have identified face in webcam image using opencv face cascade classifiers.
how can crop face fit in size of 300x300?
please code lines new opencv.
here small sample crop , resize faces:
#include <opencv2\opencv.hpp> using namespace cv; int main() { mat3b img = imread("path_to_image"); // find rectface through face detection // here values hardcoded rect rectface(235, 30, 45, 55); mat3b detection = img.clone(); rectangle(detection, rectface, scalar(0,255,0)); // crop image mat3b face(img(rectface)); // resize face 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; }
detected face:
cropped face:
resized face:
Comments
Post a Comment