-
Notifications
You must be signed in to change notification settings - Fork 11
/
ciFaceTracker.h
executable file
·129 lines (103 loc) · 3.16 KB
/
ciFaceTracker.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
/*
ciFaceTracker provides an interface to Jason Saragih's FaceTracker library.
Ported from Kyle McDonald's ofxFaceTracker by Patrick Hebron.
getImagePoint()/getImageMesh() are in image space. This means that all the
points will line up with the pixel coordinates of the image you fed into
ciFaceTracker.
getObjectPoint()/getObjectMesh() are in 3d object space. This is a product of
the mean mesh with only the expression applied. There is no rotation or
translation applied to the object space.
getMeanObjectPoint()/getMeanObjectMesh() are also in 3d object space. However,
there is no expression applied to the mesh.
*/
#pragma once
#include <sstream>
#include "cinder/app/AppBasic.h"
#include "cinder/gl/gl.h"
#include "cinder/Vector.h"
#include "cinder/TriMesh.h"
#include "CinderOpenCv.h"
#include "Tracker.h"
#include "ExpressionClassifier.h"
using namespace ci;
using namespace ci::app;
using namespace std;
using namespace FACETRACKER;
class ciFaceTracker {
public:
ciFaceTracker();
void setup();
virtual bool update(cv::Mat image);
void draw(bool drawLabels = false) const;
void reset();
int size() const;
bool getFound() const;
int getAge() const;
virtual bool getVisibility(int i) const;
vector<Vec3f> getImagePoints() const;
vector<Vec3f> getObjectPoints() const;
vector<Vec3f> getMeanObjectPoints() const;
virtual Vec3f getImagePoint(int i) const;
virtual Vec3f getObjectPoint(int i) const;
virtual Vec3f getMeanObjectPoint(int i) const;
TriMesh getImageMesh() const;
TriMesh getObjectMesh() const;
TriMesh getMeanObjectMesh() const;
TriMesh getMesh(vector<Vec3f> points) const;
virtual const cv::Mat& getObjectPointsMat() const;
virtual Vec2f getPosition() const;
virtual float getScale() const;
virtual Vec3f getOrientation() const;
Matrix44f getRotationMatrix() const;
enum Direction {
FACING_FORWARD,
FACING_LEFT, FACING_RIGHT,
FACING_UNKNOWN
};
Direction getDirection() const;
enum Feature {
LEFT_EYEBROW, RIGHT_EYEBROW,
LEFT_EYE, RIGHT_EYE,
LEFT_JAW, RIGHT_JAW, JAW,
OUTER_MOUTH, INNER_MOUTH,
NOSE_BRIDGE, NOSE_BASE,
FACE_OUTLINE, ALL_FEATURES
};
Path2d getImageFeature(Feature feature) const;
Path2d getObjectFeature(Feature feature) const;
Path2d getMeanObjectFeature(Feature feature) const;
enum Gesture {
MOUTH_WIDTH, MOUTH_HEIGHT,
LEFT_EYEBROW_HEIGHT, RIGHT_EYEBROW_HEIGHT,
LEFT_EYE_OPENNESS, RIGHT_EYE_OPENNESS,
JAW_OPENNESS,
NOSTRIL_FLARE
};
float getGesture(Gesture gesture) const;
void setRescale(float rescale);
void setIterations(int iterations);
void setClamp(float clamp);
void setTolerance(float tolerance);
void setAttempts(int attempts);
void setUseInvisible(bool useInvisible);
protected:
void updateObjectPoints();
void addTriangleIndices(TriMesh& mesh) const;
static vector<int> getFeatureIndices(Feature feature);
Path2d getFeature(Feature feature, vector<Vec3f> points) const;
bool failed;
int age;
int currentView;
bool fcheck;
double rescale;
int frameSkip;
vector<int> wSize1, wSize2;
int iterations;
int attempts;
double clamp, tolerance;
bool useInvisible;
FACETRACKER::Tracker tracker;
cv::Mat tri, con;
cv::Mat im, gray;
cv::Mat objectPoints;
};