SignalLab1/ppg.cpp

41 lines
818 B
C++

#include "opencv2/opencv.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
const int FPS = 30;
bool isDiscardData = true;
int countDiscard = 0;
const int DISCARD_DURATION = 10;
int main() {
cv::VideoCapture cap;
cap.open(0);
if (!cap.isOpened()) {
std::cerr << "[ERROR] Unable to open camera!" << std::endl;
return -2;
}
while (true) {
if(isDiscardData){
countDiscard++;
if(countDiscard == DISCARD_DURATION*FPS)
isDiscardData = false;
}
else{
cv::Mat frame;
cap.read(frame);
if (frame.empty()) {
std::cerr << "[ERROR] blank frame grabbed" << std::endl;
break;
}
cv::imshow("Color", frame);
if (cv::waitKey(1000.0 / FPS) >= 0)
break;
}
}
return 0;
}