/** Sets the unit for the length */ void cwUnitValue::setUnit(int unit) { if(Data->Unit != unit) { if(isUpdatingValue()) { //Update the value with a new value convertToUnit(unit); } Data->Unit = unit; emit unitChanged(); } }
bool FacemarkKazemiImpl::calcMeanShape (vector< vector<Point2f> >& trainlandmarks,vector<Mat>& trainimages,std::vector<Rect>& faces){ //clear the loaded meanshape if(trainimages.empty()||trainlandmarks.size()!=trainimages.size()) { // throw error if no data (or simply return -1?) CV_ErrorNoReturn(Error::StsBadArg, "Number of images is not equal to corresponding landmarks. Aborting..."); } meanshape.clear(); vector<Mat> finalimages; vector< vector<Point2f> > finallandmarks; float xmean[200] = {0.0}; //array to store mean of y coordinates float ymean[200] = {0.0}; size_t k=0; //loop to calculate mean Mat warp_mat,src,C,D; vector<Rect> facesp; Rect face; for(size_t i = 0;i < trainimages.size();i++){ src = trainimages[i].clone(); //get bounding rectangle of image for reference //function from facemark class facesp.clear(); if(!getFaces(src,facesp)){ continue; } if(facesp.size()>1||facesp.empty()) continue; face = facesp[0]; convertToUnit(face,warp_mat); //loop to bring points to a common reference and adding for(k=0;k<trainlandmarks[i].size();k++){ Point2f pt=trainlandmarks[i][k]; C = (Mat_<double>(3,1) << pt.x, pt.y, 1); D = warp_mat*C; pt.x = float(D.at<double>(0,0)); pt.y = float(D.at<double>(1,0)); trainlandmarks[i][k] = pt; xmean[k] = xmean[k]+pt.x; ymean[k] = ymean[k]+pt.y; } finalimages.push_back(trainimages[i]); finallandmarks.push_back(trainlandmarks[i]); faces.push_back(face); } //dividing by size to get mean and initialize meanshape for(size_t i=0;i<k;i++){ xmean[i]=xmean[i]/finalimages.size(); ymean[i]=ymean[i]/finalimages.size(); if(xmean[i]>maxmeanx) maxmeanx = xmean[i]; if(xmean[i]<minmeanx) minmeanx = xmean[i]; if(ymean[i]>maxmeany) maxmeany = ymean[i]; if(ymean[i]<minmeany) minmeany = ymean[i]; meanshape.push_back(Point2f(xmean[i],ymean[i])); } trainimages.clear(); trainlandmarks.clear(); trainimages = finalimages; trainlandmarks = finallandmarks; finalimages.clear(); finallandmarks.clear(); return true; }