cv::Mat CroppedImage(cv::Mat img,Landmark<cv::Point> eye,Landmark<cv::Point> lips, Landmark<cv::Point>nose) { cv::Point Eye=eye.GetLocation(); cv::Point Lips=lips.GetLocation(); cv::Point Nose=nose.GetLocation(); int minx, maxx; if(Eye.x<Nose.x) //right side { int minX=Eye.x; if (minX>Lips.x) { minX=Lips.x; } int maxX=Nose.x; minx=4*minX-3*maxX; //horizontal distance nose-eye = quarter of the face if(minx<0) { minx=0; } maxx=maxX+20;//nose supposed to be on the contour if(maxx>img.cols) { maxx=img.cols; } } else //left side { int maxX=Eye.x; if (maxX<Lips.x) { maxX=Lips.x; } int minX=Nose.x; minx=minX-20; if(minx<0) { minx=0; } maxx=4*maxX-3*-minX;//nose supposed to be on the contour if(maxx>img.cols) { maxx=img.cols; } } int minY=Eye.y; int maxY=Nose.y; int miny=4*minY-3*maxY; //vertical distance nose-eye = 1/7 of the face if(miny<0) { miny=0; } int maxy=4*maxY-3*minY; if(maxy>img.rows) { maxy=img.rows; } cv::Rect roi(minx,miny,maxx-minx,maxy-miny); cv::Mat crop=img(roi); return crop; }
std::vector<cv::Mat> Backgroung(cv::Mat img,Landmark<cv::Point> eye,Landmark<cv::Point> lips, Landmark<cv::Point>nose) { cv::Point Eye=eye.GetLocation(); cv::Point Lips=lips.GetLocation(); cv::Point Nose=nose.GetLocation(); int minx, maxx; if(Eye.x<Nose.x) //right side { int minX=Eye.x; if (minX>Lips.x) { minX=Lips.x; } int maxX=Nose.x; minx=4*minX-3*maxX; //horizontal distance nose-eye = quarter of the face if(minx<0) { minx=0; } maxx=maxX+20;//nose supposed to be on the contour if(maxx>img.cols) { maxx=img.cols; }std::cout<<"he"<<std::endl; } else //left side { int maxX=Eye.x; if (maxX<Lips.x) { maxX=Lips.x; } int minX=Nose.x; minx=minX-20; if(minx<0) { minx=0; } maxx=/*maxX+3*(maxX-minX)*/4*maxX-3*minX;//nose supposed to be on the contour if(maxx>img.cols) { maxx=img.cols; } } int minY=Eye.y; int maxY=Nose.y; int miny=4*minY-3*maxY; //vertical distance nose-eye = 1/7 of the face if(miny<0) { miny=0; } int maxy=4*maxY-3*minY; if(maxy>img.rows) { maxy=img.rows; } std::vector<cv::Mat> bg; if (minx!=0 && miny!=0) { bg.push_back(img(cv::Rect(0,0,minx,miny))); } if (minx!=0 ) { bg.push_back(img(cv::Rect(0,miny,minx,maxy-miny))); } if (miny!=0 ) { bg.push_back(img(cv::Rect(minx,0,maxx-minx,miny))); } if (minx!=0 && maxy!=img.rows) { bg.push_back(img(cv::Rect(0,maxy,minx,img.rows-maxy))); } if (miny!=0 && maxx!=img.cols) { bg.push_back(img(cv::Rect(maxx,0,img.cols-maxx,miny))); } if (maxy!=img.rows) { bg.push_back(img(cv::Rect(minx,maxy,maxx-minx,img.rows-maxy))); } if(maxx!=img.cols) { bg.push_back(img(cv::Rect(maxx,miny,img.cols-maxx,maxy-miny))); } if (maxx!=img.cols && maxy!=img.rows) { bg.push_back(img(cv::Rect(maxx,maxy,img.cols-maxx,img.rows-maxy))); } return bg; }