Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/learnopencv
Path: blob/master/FacialLandmarkDetection/renderFace.hpp
3118 views
1
#ifndef _renderFace_H_
2
#define _renderFace_H_
3
4
using namespace cv;
5
using namespace std;
6
7
#define COLOR Scalar(255, 200,0)
8
9
// drawPolyLine draws a poly line by joining
10
// successive points between the start and end indices.
11
void drawPolyline
12
(
13
Mat &im,
14
const vector<Point2f> &landmarks,
15
const int start,
16
const int end,
17
bool isClosed = false
18
)
19
{
20
// Gather all points between the start and end indices
21
vector <Point> points;
22
for (int i = start; i <= end; i++)
23
{
24
points.push_back(cv::Point(landmarks[i].x, landmarks[i].y));
25
}
26
// Draw polylines.
27
polylines(im, points, isClosed, COLOR, 2, 16);
28
29
}
30
31
32
void renderFace(cv::Mat &im, vector<Point2f> &landmarks)
33
{
34
// Draw face for the 68-point model.
35
if (landmarks.size() == 68)
36
{
37
drawPolyline(im, landmarks, 0, 16); // Jaw line
38
drawPolyline(im, landmarks, 17, 21); // Left eyebrow
39
drawPolyline(im, landmarks, 22, 26); // Right eyebrow
40
drawPolyline(im, landmarks, 27, 30); // Nose bridge
41
drawPolyline(im, landmarks, 30, 35, true); // Lower nose
42
drawPolyline(im, landmarks, 36, 41, true); // Left eye
43
drawPolyline(im, landmarks, 42, 47, true); // Right Eye
44
drawPolyline(im, landmarks, 48, 59, true); // Outer lip
45
drawPolyline(im, landmarks, 60, 67, true); // Inner lip
46
}
47
else
48
{ // If the number of points is not 68, we do not know which
49
// points correspond to which facial features. So, we draw
50
// one dot per landamrk.
51
for(int i = 0; i < landmarks.size(); i++)
52
{
53
circle(im,landmarks[i],3, COLOR, FILLED);
54
}
55
}
56
57
}
58
59
#endif // _renderFace_H_
60