-
Notifications
You must be signed in to change notification settings - Fork 232
/
LBF.h
executable file
·113 lines (104 loc) · 3.97 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
//
// 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 <opencv/cv.h>
#include <ctime>
#include <string>
#include <limits>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <numeric>
#include <utility>
struct Params{
double bagging_overlap;
int max_numtrees;
int max_depth;
int landmark_num;// to be decided
int initial_num;
int max_numstage;
double max_radio_radius[10];
int max_numfeats[10]; // number of pixel pairs
int max_numthreshs;
};
extern Params global_params;
extern std::string modelPath;
extern std::string dataPath;
class BoundingBox{
public:
double start_x;
double start_y;
double width;
double height;
double centroid_x;
double centroid_y;
BoundingBox(){
start_x = 0;
start_y = 0;
width = 0;
height = 0;
centroid_x = 0;
centroid_y = 0;
};
};
cv::Mat_<double> GetMeanShape(const std::vector<cv::Mat_<double> >& shapes,
const std::vector<BoundingBox>& bounding_box);
void GetShapeResidual(const std::vector<cv::Mat_<double> >& ground_truth_shapes,
const std::vector<cv::Mat_<double> >& current_shapes,
const std::vector<BoundingBox>& bounding_boxs,
const cv::Mat_<double>& mean_shape,
std::vector<cv::Mat_<double> >& shape_residuals);
cv::Mat_<double> ProjectShape(const cv::Mat_<double>& shape, const BoundingBox& bounding_box);
cv::Mat_<double> ReProjectShape(const cv::Mat_<double>& shape, const BoundingBox& bounding_box);
void SimilarityTransform(const cv::Mat_<double>& shape1, const cv::Mat_<double>& shape2,
cv::Mat_<double>& rotation,double& scale);
double calculate_covariance(const std::vector<double>& v_1,
const std::vector<double>& v_2);
void LoadData(std::string filepath,
std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<double> >& ground_truth_shapes,
std::vector<BoundingBox> & bounding_box);
void LoadDataAdjust(std::string filepath,
std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<double> >& ground_truth_shapes,
std::vector<BoundingBox> & bounding_box);
void LoadOpencvBbxData(std::string filepath,
std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<double> >& ground_truth_shapes,
std::vector<BoundingBox> & bounding_boxs
);
void LoadCofwTrainData(std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<double> >& ground_truth_shapes,
std::vector<BoundingBox>& bounding_boxs);
void LoadCofwTestData(std::vector<cv::Mat_<uchar> >& images,
std::vector<cv::Mat_<double> >& ground_truth_shapes,
std::vector<BoundingBox>& bounding_boxs);
BoundingBox CalculateBoundingBox(cv::Mat_<double>& shape);
cv::Mat_<double> LoadGroundTruthShape(std::string& filename);
void adjustImage(cv::Mat_<uchar>& img,
cv::Mat_<double>& ground_truth_shape,
BoundingBox& bounding_box);
void TrainModel(std::vector<std::string> trainDataName);
double TestModel(std::vector<std::string> testDataName);
int FaceDetectionAndAlignment(const char* inputname);
void ReadGlobalParamFromFile(std::string path);
double CalculateError(const cv::Mat_<double>& ground_truth_shape, const cv::Mat_<double>& predicted_shape);
#endif