-
Notifications
You must be signed in to change notification settings - Fork 6
/
LBFModel.h
85 lines (71 loc) · 2.2 KB
/
LBFModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "common.h"
#include "numerical.hpp"
#include "regressiontree.hpp"
#include "regressionforest.hpp"
#include "utils.h"
#include "transformations.h"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
struct ImageData {
bool loadImage(const string &filename);
bool loadPoints(const string &filename);
cv::Mat img; // resized grayscale image for training
cv::Mat original;
Eigen::VectorXd pts; // rescaled points, x1 y1 x2 y2 ... xn yn
};
struct TrainingSample {
vector<int> imgidx; // index vector of the training samples, N
Eigen::MatrixXd truth; // N x Lfp matrix
Eigen::MatrixXd guess; // N x Lfp matrix
};
class LBFModel
{
public:
LBFModel(){}
LBFModel(const string &modelfile) { load(modelfile); }
~LBFModel(){}
bool train(const string &settingsfile);
bool test(const string &imagefile);
bool batch_test(const string &settingsfile);
bool load(const string &modelfile);
bool save(const string &modelfile);
private:
map<string, string> readSettingFile(const string &filename);
vector<ImageData> loadInputImages(const map<string, string> &configs);
TrainingSample generateTrainingSamples(vector<ImageData> &inputimages);
void trainModel(vector<ImageData> &imgdata, TrainingSample &samples);
private:
struct ModelParameters {
ModelParameters() :Ndims(500), Npixels(400){}
int window_size;
int T; // number of stages
int N; // number of trees per stage
int D; // depth of decision trees
int Ndims;
int Npixels;
void print() {
cout << "window size = " << window_size << endl;
cout << "T = " << T << endl;
cout << "N = " << N << endl;
cout << "D = " << D << endl;
}
} params;
// the model
// the trees
typedef RegressionTree<> tree_t;
typedef RegressionForest<tree_t> forest_t;
struct PixelOffset {
double x, y;
};
struct LandmarkMappingFunction {
Eigen::MatrixXd locations; // pixel offsets w.r.t. the landmark in mean shape
forest_t forest;
};
typedef vector<LandmarkMappingFunction> MappingFunction;
struct Stage {
MappingFunction phi; // feature mapping function
Eigen::MatrixXd W; // weighting matrix
};
vector<MappingFunction> stages;
};