-
Notifications
You must be signed in to change notification settings - Fork 0
/
LBF.h
139 lines (122 loc) · 4.7 KB
/
LBF.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// LBF.h
// myopencv
//
// Created by lequan on 1/24/15.
// Copyright (c) 2015 lequan. All rights reserved.
//
#ifndef FACE_ALIGNMENT_H
#define FACE_ALIGNMENT_H
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <cctype>
#include <iostream>
#include <iterator>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "cv.h"
#include <ctime>
#include <string>
#include <limits>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <numeric>
#include <utility>
struct Params{
float bagging_overlap;
int max_numtrees;
int max_depth;
int landmark_num;// to be decided
int initial_num;
int max_numstage;
float max_radio_radius[10];
int max_numfeats[10]; // number of pixel pairs
int max_numthreshs;
float max_probility[10];
};
extern Params global_params;
extern cv::string modelPath;
extern cv::string dataPath;
class BoundingBox{
public:
float start_x;
float start_y;
float width;
float height;
float centroid_x;
float centroid_y;
BoundingBox(){
start_x = 0;
start_y = 0;
width = 0;
height = 0;
centroid_x = 0;
centroid_y = 0;
};
};
cv::Mat_<float> GetMeanShape(const std::vector<cv::Mat_<float> >& shapes,
const std::vector<BoundingBox>& bounding_box);
cv::Mat_<float> GetMeanShape2(const std::vector<cv::Mat_<float> >& shapes,
const std::vector<BoundingBox>& bounding_box,const std::vector<int>& ground_truth_faces);
void GetShapeResidual(const std::vector<cv::Mat_<float> >& ground_truth_shapes,
const std::vector<cv::Mat_<float> >& current_shapes,
const std::vector<BoundingBox>& bounding_boxs,
const cv::Mat_<float>& mean_shape,
std::vector<cv::Mat_<float> >& shape_residuals);
cv::Mat_<float> ProjectShape(const cv::Mat_<float>& shape, const BoundingBox& bounding_box);
cv::Mat_<float> ReProjectShape(const cv::Mat_<float>& shape, const BoundingBox& bounding_box);
void SimilarityTransform(const cv::Mat_<float>& shape1, const cv::Mat_<float>& shape2,
cv::Mat_<float>& rotation,float& scale);
float calculate_covariance(const std::vector<float>& v_1,
const std::vector<float>& v_2);
void LoadData(std::string filepath,
std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<float> >& ground_truth_shapes,
std::vector<BoundingBox> & bounding_box);
void LoadDataAdjust(std::string filepath,
std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<float> >& ground_truth_shapes,
std::vector<BoundingBox> & bounding_box);
void LoadDataAdjust2(std::string filepath,
std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<float> >& ground_truth_shapes,
std::vector<int>& ground_truth_faces,
std::vector<BoundingBox> & bounding_box);
void LoadOpencvBbxData(std::string filepath,
std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<float> >& ground_truth_shapes,
std::vector<BoundingBox> & bounding_boxs
);
void LoadCofwTrainData(std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<float> >& ground_truth_shapes,
std::vector<BoundingBox>& bounding_boxs);
void LoadCofwTestData(std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<float> >& ground_truth_shapes,
std::vector<BoundingBox>& bounding_boxs);
BoundingBox CalculateBoundingBox(cv::Mat_<float>& shape);
BoundingBox CalculateBoundingBox2(cv::Mat_<float>& shape);
cv::Mat_<float> LoadGroundTruthShape(std::string& filename);
void adjustImage(cv::Mat_<uchar>& img,
cv::Mat_<float>& ground_truth_shape,
BoundingBox& bounding_box);
void adjustImage2(cv::Mat_<uchar>& img,
cv::Mat_<float>& ground_truth_shape,
BoundingBox& bounding_box);
void TrainModel(std::vector<std::string> trainDataName);
float TestModel(std::vector<std::string> testDataName);
int FaceDetectionAndAlignment(const char* inputname);
void ReadGlobalParamFromFile(cv::string path);
float CalculateError(const cv::Mat_<float>& ground_truth_shape, const cv::Mat_<float>& predicted_shape);
void getRandomBox(const cv::Mat_<uchar>& image, const BoundingBox& old_box, BoundingBox& new_box);
#define SAVEBIN (0)
#define MAXHEIGHT (120)
#define MAXHEIGHT2 (240)
#define ONLYSHAPE (1)
#define MINHEIGHT (10)
#endif