static void FlipIfLeftFacing( Shape& shape, // io EYAW eyaw, // in int ncols) // in { if (IsLeftFacing(eyaw)) shape = FlipShape(shape, ncols); }
void PinnedStartShapeAndRoi( // use the pinned landmarks to init the start shape Shape& startshape, // out: the start shape (in ROI frame) Image& face_roi, // out: ROI around face, possibly rotated upright DetPar& detpar_roi, // out: detpar wrt to face_roi DetPar& detpar, // out: detpar wrt to img Shape& pinned_roi, // out: pinned arg translated to ROI frame const Image& img, // in: the image (grayscale) const vec_Mod& mods, // in: a vector of models, one for each yaw range const Shape& pinned) // in: manually pinned landmarks { double rot, yaw; EstRotAndYawFrom5PointShape(rot, yaw, As5PointShape(pinned, mods[0]->MeanShape_())); const EYAW eyaw = DegreesAsEyaw(yaw, NSIZE(mods)); const int imod = EyawAsModIndex(eyaw, mods); // select ASM model based on yaw if (trace_g) lprintf("%-6.6s yaw %3.0f rot %3.0f ", EyawAsString(eyaw), yaw, rot); pinned_roi = pinned; // use pinned_roi as a temp shape we can change Image workimg(img); // possibly flipped image if (IsLeftFacing(eyaw)) // left facing? (our models are for right facing faces) { pinned_roi = FlipShape(pinned_roi, workimg.cols); FlipImgInPlace(workimg); } const Mod* mod = mods[ABS(imod)]; startshape = PinMeanShape(pinned_roi, mod->MeanShape_()); startshape = mod->ConformShapeToMod_Pinned_(startshape, pinned_roi); detpar = PseudoDetParFromStartShape(startshape, rot, yaw, NSIZE(mods)); if (IsLeftFacing(eyaw)) detpar.rot *= -1; FaceRoiAndDetPar(face_roi, detpar_roi, workimg, detpar, false); startshape = ImgShapeToRoiFrame(startshape, detpar_roi, detpar); pinned_roi = ImgShapeToRoiFrame(pinned_roi, detpar_roi, detpar); // following line not strictly necessary because don't actually need eyes/mouth InitDetParEyeMouthFromShape(detpar_roi, startshape); if (IsLeftFacing(eyaw)) { detpar = FlipDetPar(detpar, img.cols); detpar.rot = -detpar.rot; detpar_roi.x += 2. * (face_roi.cols/2. - detpar_roi.x); } }
Shape RoiShapeToImgFrame( // return shape in image frame const Shape& shape, // in: shape in roi frame const Image& face_roi, // in const DetPar& detpar_roi, // in: detpar wrt the ROI const DetPar& detpar) // in: detpar wrt the image { Shape outshape(shape.clone()); if (IsLeftFacing(detpar.eyaw)) outshape = FlipShape(outshape, face_roi.cols); if (Valid(detpar.rot) && detpar.rot) { const MAT rotmat = getRotationMatrix2D(cv::Point2f(float(detpar_roi.x), float(detpar_roi.y)), detpar.rot, 1.); TransformShapeInPlace(outshape, rotmat); } return ShiftShape(outshape, detpar.x - detpar_roi.x, detpar.y - detpar_roi.y); }