-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathTrainDemo.cpp
More file actions
63 lines (56 loc) · 2.39 KB
/
TrainDemo.cpp
File metadata and controls
63 lines (56 loc) · 2.39 KB
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
#include "LBFRegressor.h"
using namespace std;
using namespace cv;
void LoadCofwTrainData(vector<Mat_<uchar> >& images,
vector<Mat_<double> >& ground_truth_shapes,
vector<BoundingBox>& bounding_boxs);
void TrainDemo(){
vector<Mat_<uchar> > images;
vector<Mat_<double> > ground_truth_shapes;
vector<BoundingBox> bounding_boxs;
// you need to modify this section according to your training dataset
string traindatapath1 = dataPath+"helen_trainset/Path_Images.txt";
string traindatapath2 = dataPath+"afw/Path_Images.txt";
string traindatapath3 = dataPath+"lfpw_trainset/Path_Images.txt";
LBFRegressor regressor;
LoadOpencvBbxData(traindatapath1, images, ground_truth_shapes, bounding_boxs);
LoadOpencvBbxData(traindatapath2, images, ground_truth_shapes, bounding_boxs);
LoadOpencvBbxData(traindatapath3, images, ground_truth_shapes, bounding_boxs);
regressor.Train(images,ground_truth_shapes,bounding_boxs);
regressor.Save(modelPath+"LBF.model");
return;
}
void LoadCofwTrainData(vector<Mat_<uchar> >& images,
vector<Mat_<double> >& ground_truth_shapes,
vector<BoundingBox>& bounding_boxs){
int img_num = 1345;
cout<<"Read images..."<<endl;
for(int i = 0;i < img_num;i++){
string image_name = "/Users/lequan/workspace/xcode/myopencv/COFW_Dataset/trainingImages/";
image_name = image_name + to_string(i+1) + ".jpg";
Mat_<uchar> temp = imread(image_name,0);
images.push_back(temp);
}
ifstream fin;
fin.open("/Users/lequan/workspace/xcode/myopencv/COFW_Dataset/boundingbox.txt");
for(int i = 0;i < img_num;i++){
BoundingBox temp;
fin>>temp.start_x>>temp.start_y>>temp.width>>temp.height;
temp.centroid_x = temp.start_x + temp.width/2.0;
temp.centroid_y = temp.start_y + temp.height/2.0;
bounding_boxs.push_back(temp);
}
fin.close();
fin.open("/Users/lequan/workspace/xcode/myopencv/COFW_Dataset/keypoints.txt");
for(int i = 0;i < img_num;i++){
Mat_<double> temp(global_params.landmark_num,2);
for(int j = 0;j < global_params.landmark_num;j++){
fin>>temp(j,0);
}
for(int j = 0;j < global_params.landmark_num;j++){
fin>>temp(j,1);
}
ground_truth_shapes.push_back(temp);
}
fin.close();
}