This commit is contained in:
Ly PECHVATTANA 2023-02-24 11:07:38 +01:00
parent 76f2e9de06
commit c4c266ae6a
2 changed files with 26175 additions and 1 deletions

File diff suppressed because it is too large Load Diff

15
ppg.cpp
View File

@ -1,3 +1,4 @@
#include "opencv2/opencv.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
@ -12,7 +13,13 @@ const int DISCARD_DURATION = 10;
int main() {
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;
return -1;
};
cv::Rect foreheadROI;
if (!cap.isOpened()) {
std::cerr << "[ERROR] Unable to open camera!" << std::endl;
return -2;
@ -31,6 +38,12 @@ int main() {
std::cerr << "[ERROR] blank frame grabbed" << std::endl;
break;
}
std::vector<cv::Rect> faceRectangles;
faceDetector.detectMultiScale(frame, faceRectangles, 1.1, 3, 0,cv::Size(20, 20));
foreheadROI = faceRectangles[0];
foreheadROI.height *= 0.3;
cv::rectangle(frame, faceRectangles[0], cv::Scalar(0, 0, 255), 1, 1, 0);
cv::rectangle(frame, foreheadROI, cv::Scalar(0, 255, 0), 1, 1, 0);
cv::imshow("Color", frame);
if (cv::waitKey(1000.0 / FPS) >= 0)
break;