void Mod::LevSearch_( // do an ASM search at one level in the image pyr Shape& shape, // io: the face shape for this pyramid level int ilev, // in: pyramid level (0 is full size) const Image& img, // in: image scaled to this pyramid level const Shape& pinnedshape) // in: if no rows then no pinned landmarks, else // points except those equal to 0,0 are pinned const { TraceShape(shape, img, ilev, 0, "enterlevsearch"); InitHatLevData(img, ilev); // init internal HAT mats for this lev VEC b(NSIZE(shapemod_.eigvals_), 1, 0.); // eigvec weights, init to 0 for (int iter = 0; iter < SHAPEMODEL_ITERS; iter++) { // suggest shape by descriptor matching at each landmark SuggestShape_(shape, ilev, img, pinnedshape); TraceShape(shape, img, ilev, iter, "suggested"); // adjust suggested shape to conform to the shape model if (pinnedshape.rows) shape = shapemod_.ConformShapeToMod_Pinned_(b, shape, ilev, pinnedshape); else shape = shapemod_.ConformShapeToMod_(b, shape, ilev); TraceShape(shape, img, ilev, iter, "conformed"); } }
static void GenTrainingDescsForOneImg( TRAIN_DISTS& train_dists, // io: [ipoint] [idesc] new distances will be added TRAIN_DESCS& train_descs, // io: [ipoint] [idesc] new descriptors will be added int ilev, // in: pyramid level (0 is full scale) const ShapeFile& sh, // in int ishape) // in: shape index in the shapefile { Image img; // image scaled to EYEMOUTH_DIST and ilev Shape shape; // shape scaled ditto GetTrainImg(img, shape, ilev, sh, ishape); // init internal HAT mats for this lev so can call HatDesc later InitHatLevData(img, ilev); for (int ipoint = 0; ipoint < shape.rows; ipoint++) { if (PointUsableForTraining(shape, ipoint, sh.bits_[ishape], sh.bases_[ishape].c_str())) { const bool is_hat = IsTasmHatDesc(ilev, ipoint); const VEC desc( is_hat? HatDesc(shape(ipoint, IX), shape(ipoint, IY)): ClassicProf(img, shape, ipoint, TASM_1D_PROFLEN)); train_dists[ipoint].push_back(0); // positive case so distance is zero train_descs[ipoint].push_back(desc); if (is_hat) // get the negative descriptors too? for (int ineg = 0; ineg < TASM_NNEG_TRAIN_DESCS; ineg++) { // get descriptor at at a random xy offset from the true position int xneg, yneg; NegOffsets(xneg, yneg); const VEC neg_desc(HatDesc(shape(ipoint, IX) + xneg, shape(ipoint, IY) + yneg)); train_dists[ipoint].push_back(sqrt(double(SQ(xneg)+SQ(yneg)))); train_descs[ipoint].push_back(neg_desc); } } } }