问题描述
我已使用 OpenCv
成功侦测到背景中有其他东西的图片。
现在我需要只提取被检测的部分(ie face),并将其转换成一些图像格式,如 jpeg
或 gif $
I have successfully detected a face out of an image having other things in background using OpenCv
.Now I need to extract just the detected part (i.e. face) and convert it into some image format like jpeg
or gif
to make a face database to use for my neural net training.
我如何做到这一点?
推荐答案
一旦你检测到面部,你会得到一个矩形的对角,用于在面部绘制矩形。
Once you detect the faces, you get opposite corners of a rectangle, which is used to draw rectangles around the face.
现在您可以设置图像ROI(感兴趣区域),裁剪ROI并将其另存为另一个图像。
Now you can set image ROI ( Region of Interest) , crop the ROI and save it as another image.
/* After detecting the rectangle points, Do as follows */
/* sets the Region of Interest
Note that the rectangle area has to be __INSIDE__ the image */
cvSetImageROI(img1, cvRect(10, 15, 150, 250));
/* create destination image
Note that cvGetSize will return the width and the height of ROI */
IplImage *img2 = cvCreateImage(cvGetSize(img1),
img1->depth,
img1->nChannels);
/* copy subimage */
cvCopy(img1, img2, NULL);
/* always reset the Region of Interest */
cvResetImageROI(img1);
上述代码取自)
进一步 cvSaveImage
函数可用于将图像保存到文件。
Further cvSaveImage
function can be used to save image to a file.
这篇关于如何从图像提取面部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!