-
Notifications
You must be signed in to change notification settings - Fork 146
/
RPPG.hpp
123 lines (98 loc) · 2.52 KB
/
RPPG.hpp
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
//
// RPPG.hpp
// Heartbeat
//
// Created by Philipp Rouast on 7/07/2016.
// Copyright © 2016 Philipp Roüast. All rights reserved.
//
#ifndef RPPG_hpp
#define RPPG_hpp
#include <fstream>
#include <string>
#include <opencv2/objdetect.hpp>
#include <opencv2/dnn.hpp>
#include <stdio.h>
using namespace cv;
using namespace dnn;
using namespace std;
enum rPPGAlgorithm { g, pca, xminay };
enum faceDetAlgorithm { haar, deep };
class RPPG {
public:
// Constructor
RPPG() {;}
// Load Settings
bool load(const rPPGAlgorithm rPPGAlg, const faceDetAlgorithm faceDetAlg,
const int width, const int height, const double timeBase, const int downsample,
const double samplingFrequency, const double rescanFrequency,
const int minSignalSize, const int maxSignalSize,
const string &logPath, const string &haarPath,
const string &dnnProtoPath, const string &dnnModelPath,
const bool log, const bool gui);
void processFrame(Mat &frameRGB, Mat &frameGray, int time);
void exit();
typedef vector<Point2f> Contour2f;
private:
void detectFace(Mat &frameRGB, Mat &frameGray);
void setNearestBox(vector<Rect> boxes);
void detectCorners(Mat &frameGray);
void trackFace(Mat &frameGray);
void updateMask(Mat &frameGray);
void updateROI();
void extractSignal_g();
void extractSignal_pca();
void extractSignal_xminay();
void estimateHeartrate();
void draw(Mat &frameRGB);
void invalidateFace();
void log();
// The algorithm
rPPGAlgorithm rPPGAlg;
// The classifier
faceDetAlgorithm faceDetAlg;
CascadeClassifier haarClassifier;
Net dnnClassifier;
// Settings
Size minFaceSize;
int maxSignalSize;
int minSignalSize;
double rescanFrequency;
double samplingFrequency;
double timeBase;
bool logMode;
bool guiMode;
// State variables
int64_t time;
double fps;
int high;
int64_t lastSamplingTime;
int64_t lastScanTime;
int low;
int64_t now;
bool faceValid;
bool rescanFlag;
// Tracking
Mat lastFrameGray;
Contour2f corners;
// Mask
Rect box;
Mat1b mask;
Rect roi;
// Raw signal
Mat1d s;
Mat1d t;
Mat1b re;
// Estimation
Mat1d s_f;
Mat1d bpms;
Mat1d powerSpectrum;
double bpm = 0.0;
double meanBpm;
double minBpm;
double maxBpm;
// Logfiles
ofstream logfile;
ofstream logfileDetailed;
string logfilepath;
};
#endif /* RPPG_hpp */