我下载的是Stasm 4.1.0版本。
包含的是模型的实现。主要的源码文件是 stasm_lib.cpp,其中的函数stasm_search_single()是主要接口函数,在给定的一张人脸图片中搜索landmark点。
1、MOD_1文件夹对ASM进行初始化,给出特征向量、特征值以及对b的约束值,是一个已经训练好的模型。 MOD_1/initasm.cpp: 函数:
void InitMods( // initialize 一个 ASM model vec_Mod& mods, // out: ASM model (only one model in this version of Stasm) const char* datadir) // in: directory of face detector files2、Shapemod.cpp: 变量:
static const int SHAPEHACK_MINPYRLEV = 2;函数:
static void LimitB( VEC& b, // io: eigvec weights const VEC& eigvals, // in double bmax) // in 对b约束到bmax * sqrt(lambda_i)
Shape ConformShapeToMod( // Return a copy of inshape conformed to the model VEC& b, // io: eigvec weights, 2n x 1 const Shape& inshape, // in: the current position of the landmarks const Shape& meanshape, // in: n x 2 const VEC& eigvals, // in: neigs x 1 const MAT& eigvecs, // in: 2n x neigs const MAT& eigvecsi, // in: neigs x 2n, inverse of eigvecs const double bmax, // in: for LimitB const VEC& pointweights) // in: contribution of each point to the pose 这个函数拟合模型到新的形状,是形状模型中非常重要的一步。
3、asm.cpp:
typedef vector<const Mod*> vec_Mod;类Mod:用来找到landmark点的ASM模型 成员变量:
成员函数:
构造函数:
Shape ModSearch_( // returns coords of the facial landmarks const Shape& startshape, // in: startshape roughly positioned on face const Image& img, // in: grayscale image (typically just ROI) const Shape* pinnedshape=NULL) // in: pinned landmarks, NULL if nothing pinned4、stasm_lib.cpp 变量:
static vec_Mod mods_g; // the ASM model(s)static FaceDet facedet_g; // the face detector
static Image img_g; // the current image
函数:
int stasm_search_single( // wrapper for stasm_search_auto and friends int* foundface, // out: 0=no face, 1=found face float* landmarks, // out: x0, y0, x1, y1, ..., caller must allocate const char* img, // in: gray image data, top left corner at 0,0 int width, // in: image width int height, // in: image height const char* imgpath, // in: image path, used only for err msgs and debug const char* datadir) // in: directory of face detector files 根据输入的图片数据及信息,得到其中的landmark点
int stasm_open_image_ext( // extended version of stasm_open_image const char* img, // in: gray image data, top left corner at 0,0 int width, // in: image width int height, // in: image height const char* imgpath, // in: image path, used only for err msgs and debug int multiface, // in: 0=return only one face, 1=allow multiple faces int minwidth, // in: min face width as percentage of img width void* user) // in: NULL or pointer to user abort func
包含了各种测试程序。