-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheadposeestimator.cpp
119 lines (98 loc) · 2.75 KB
/
headposeestimator.cpp
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
#include "headposeestimator.h"
HeadPoseEstimator::HeadPoseEstimator(opengl_view *renderWidget, QObject *parent) : QObject(parent)
{
//Initialize
m_webcam.initialize(0);
m_renderer.initialize(renderWidget);
m_head_pose_detector.initialize();
m_vertex_generator.initialize();
m_snapchatdog_filter.initialize();
m_fancyman_filter.initialize();
m_face_rectangles.initialize();
m_faceswap_generator.initialize(QApplication::applicationDirPath()+"\\overlays\\Obama.png");
if(m_face_detector.initialize(2.0)!=0)
{
return;
}
// Form processing chain
m_webcam.setNextItem(&m_face_detector);
m_face_detector.setNextItem(&m_face_rectangles);
m_face_rectangles.setNextItem(&m_head_pose_detector);
m_head_pose_detector.setNextItem(&m_vertex_generator);
m_vertex_generator.setNextItem(&m_faceswap_generator);
m_faceswap_generator.setNextItem(&m_snapchatdog_filter);
m_snapchatdog_filter.setNextItem(&m_fancyman_filter);
m_fancyman_filter.setNextItem(&m_renderer);
//Connect loop timer with run method
connect(&m_loop_timer,SIGNAL(timeout()),this,SLOT(run()));
m_running = false;
}
HeadPoseEstimator::~HeadPoseEstimator()
{
m_webcam.stop();
}
void HeadPoseEstimator::processWebcam(bool process)
{
if(process==true)
{
m_webcam.start();
m_loop_timer.start(1);
m_running = true;
}
else
{
m_webcam.stop();
m_loop_timer.stop();
m_running = false;
}
}
void HeadPoseEstimator::showFacePoints(bool show)
{
m_face_detector.setEnabled(show);
}
void HeadPoseEstimator::showHeadAngles(bool show)
{
m_head_pose_detector.setEnabled(show);
}
void HeadPoseEstimator::showVertexModel(bool show)
{
m_vertex_generator.setEnabled(show);
}
void HeadPoseEstimator::showFaceRectangles(bool show)
{
m_face_rectangles.setEnabled(show);
}
void HeadPoseEstimator::showSnapchatDogOverlay(bool show)
{
m_snapchatdog_filter.setEnabled(show);
}
void HeadPoseEstimator::showFancyManOverlay(bool show)
{
m_fancyman_filter.setEnabled(show);
}
void HeadPoseEstimator::loadNewFace(QString face_img_path)
{
if(m_faceswap_generator.isEnabled())
{
// Stop face swap generator
m_faceswap_generator.setEnabled(false);
// Reinitialize face swap generator with new image
m_faceswap_generator.initialize(face_img_path);
// Start again face swap generator
m_faceswap_generator.setEnabled(true);
return;
}
m_faceswap_generator.initialize(face_img_path);
}
void HeadPoseEstimator::swapFace(bool swap)
{
m_faceswap_generator.setEnabled(swap);
}
bool HeadPoseEstimator::isWorking()
{
return this->m_running;
}
void HeadPoseEstimator::run()
{
m_webcam.process(m_result);
}