This commit is contained in:
parent
2ff8280a01
commit
4b4681de65
29
ppg.cpp
29
ppg.cpp
|
|
@ -3,18 +3,21 @@
|
|||
#include "opencv2/videoio.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
|
||||
#define BUFFER_DURATION 30.0
|
||||
#define FPS 30.0
|
||||
#define temps 1.0
|
||||
|
||||
bool isDiscardData = true;
|
||||
int countDiscard = 0;
|
||||
bool isBufferFull = false;
|
||||
int sampleIdBuffer = 0;
|
||||
|
||||
int main() {
|
||||
std::cout << "PPG, j'adore gitbash même si avec github desktop c'est mieux" << std::endl;
|
||||
|
||||
cv::VideoCapture cap;
|
||||
cap.open(0);
|
||||
|
||||
cv::CascadeClassifier faceDetector;
|
||||
if (!faceDetector.load("./haarcascade_frontalface_alt.xml")) {
|
||||
std::cerr << "[ERROR] Unable to load face cascade" << std::endl;
|
||||
|
|
@ -48,13 +51,25 @@ int main() {
|
|||
cv::cvtColor(frame, frame_gray, cv::COLOR_BGR2GRAY);
|
||||
std::vector<cv::Rect> faceRectangles;
|
||||
faceDetector.detectMultiScale(frame_gray, faceRectangles, 1.1, 3, 0, cv::Size(20, 20));
|
||||
for (size_t i = 0; i < faceRectangles.size(); i++) {
|
||||
cv::rectangle(frame, faceRectangles[i], cv::Scalar(255, 0, 0), 2);
|
||||
cv::Rect foreheadROI = faceRectangles[i];
|
||||
foreheadROI.height *= 0.3;
|
||||
cv::rectangle(frame, foreheadROI, cv::Scalar(0, 255, 0), 2);
|
||||
}
|
||||
cv::rectangle(frame, faceRectangles[0], cv::Scalar(255, 0, 0), 2);
|
||||
cv::Rect foreheadROI = faceRectangles[0];
|
||||
foreheadROI.height *= 0.3;
|
||||
cv::rectangle(frame, foreheadROI, cv::Scalar(0, 255, 0), 2);
|
||||
cv::imshow("Color", frame);
|
||||
cv::Mat frame_forehead = frame(foreheadROI);
|
||||
cv::Scalar avg_forehead = mean(frame_forehead);
|
||||
cv::Mat greenSignal(1, FPS*BUFFER_DURATION, CV_64F);
|
||||
|
||||
|
||||
if (!isBufferFull)
|
||||
{
|
||||
greenSignal.at<double>(0, sampleIdBuffer) = avg_forehead[1] ;
|
||||
sampleIdBuffer++;
|
||||
if (sampleIdBuffer == FPS*BUFFER_DURATION)
|
||||
{
|
||||
isBufferFull = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cv::waitKey(1000.0/FPS) >= 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue