如何从图像中提取人脸
How to extract face from an image?
我使用OpenCv
成功地从背景中有其他东西的图像中检测到了一张脸。现在,我只需要提取检测到的部分(即人脸),并将其转换为jpeg
或gif
等图像格式,以创建一个人脸数据库,用于我的神经网络训练。
我该怎么做?
一旦检测到人脸,就会得到矩形的对角,用于在人脸周围绘制矩形。
现在,您可以设置图像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);
以上代码取自http://nashruddin.com/OpenCV_Region_of_Interest_(ROI)
此外,还可以使用cvSaveImage
功能将图像保存到文件中。
试试这个:
for(i=0;i<(pFaceRectSeq?pFaceRectSeq->total:0);i++)
{
CvRect* r=(CvRect*)cvGetSeqElem(pFaceRectSeq,i);
int width=r->width;
int height=r->height;
cvSetImageROI(pInpImg,*r);
IplImage* pCropImg=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,3);
cvCopy(pInpImg,pCropImg,NULL);
cvShowImage("Cropped Window",pCropImg);
cvWaitKey(0);
cvResetImageROI(pInpImg);
cvReleaseImage(&pCropImg);
}
相关文章:
- 在RAW图像中提取RGB通道值的库或方法
- 使用ffmpeg时如何提高图像导出/提取速度?
- 如何在使用OpenCV C++应用K均值后提取分割图像
- 提取带有边框环绕的图像中的子图像
- 从Dlib CNN中提取图像
- 如何从C 中的CV :: MAT图像中有效提取某些像素
- 如何从我自己的图像中提取PCD文件
- 使用OpenCV从图像中提取不同尺寸的矩形
- 图像和图像处理中的特征提取
- 如何在 OpenCv 中使用 HSV 阈值和轮廓从图像中提取皮肤
- 如何从彩色图像中提取和计算相似颜色点的数量
- C++使用逐位操作从图像中提取字符
- 如何从图像中提取ROI区域并将其显示在窗口中
- 如何从Opencv中的图像矩阵中提取数值梯度矩阵
- 如何从图像中提取FAST功能
- 提取一组样本图像的描述符,并在OpenCV中训练SVM
- 使用 GrabCut 提取背景图像
- OpenCV从正方形向量中提取图像的面积
- Qt - webkit -如何从网页中提取图像
- 使用Opencv提取图像的公共部分