2

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.

How can I do this?

4

2 に答える 2

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);

上記のコードはhttp://nashruddin.com/OpenCV_Region_of_Interest_(ROI )から取得したものです。

さらにcvSaveImage機能を使用して、画像をファイルに保存できます。

于 2012-02-03T17:21:48.410 に答える
1

これを試して:

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);
}
于 2012-08-10T10:26:02.790 に答える