为任何人生成面罩

时间:2014-03-22 02:32:34

标签: c++ opencv mask

如何使用opencv 2.4.2和C ++生成任何面部尺寸的面罩?

此处的代码为特定人员指定左侧和右侧ROI面部区域的某些值:

Mat left=imread("left.jpg");
Mat front=imread("front.jpg");
int x=30, y=10, w=240, h=200, offset_x=20, offset_y=6;
Mat leftROI=left(Rect(x,y,w,h));
Mat frontROI=front(Rect(x-offset_x,y+offset_y,w,h)); 

//create mask
Mat gray1,thr1;
cvtColor(leftROI,gray1,CV_BGR2GRAY);
threshold( gray1, thr1,190, 255,CV_THRESH_BINARY_INV );
Mat gray2,thr2;
cvtColor(frontROI,gray2,CV_BGR2GRAY);
threshold( gray2, thr2,190, 255,CV_THRESH_BINARY_INV );

但每张脸都不一样。如何为任何人生成面罩?

0 个答案:

没有答案