如何从图像中提取人脸?

Abh*_*mar 2 c++ opencv face-recognition

我已经使用OpenCv. 现在我只需要提取检测到的部分(即面部)并将其转换为某种图像格式,例如jpeggif制作面部数据库以用于我的神经网络训练。

我怎样才能做到这一点?

Abi*_*n K 5

检测到人脸后,您会得到一个矩形的对角,该矩形用于在人脸周围绘制矩形。

现在您可以设置图像 ROI(感兴趣区域),裁剪 ROI 并将其另存为另一个图像。

/* 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);
Run Code Online (Sandbox Code Playgroud)

以上代码取自http://nashruddin.com/OpenCV_Region_of_Interest_(ROI )

进一步的cvSaveImage功能可用于将图像保存到文件中。