FaceFound with opencv
This commit is contained in:
parent
546b703ff3
commit
0578aff543
File diff suppressed because it is too large
Load Diff
59
ppg.cpp
59
ppg.cpp
|
|
@ -4,8 +4,63 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
const int FPS = 30;
|
||||
bool isDiscardData = true;
|
||||
int countDiscard = 0;
|
||||
const int DISCARD_DURATION = 5;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hello World!" << std::endl;
|
||||
return 0;
|
||||
cv::VideoCapture cap;
|
||||
cap.open(0);
|
||||
if (!cap.isOpened())
|
||||
{
|
||||
std::cerr << "[ERROR] Unable to open camera!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
//If Haard Cascade not found: error
|
||||
cv::CascadeClassifier faceDetector;
|
||||
if( !faceDetector.load("./haarcascade_frontalface_alt.xml"))
|
||||
{
|
||||
std::cerr << "[ERROR] Unable to load face cascade" << std::endl;
|
||||
return -1;
|
||||
};
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (isDiscardData)
|
||||
{
|
||||
countDiscard++;
|
||||
if (countDiscard == DISCARD_DURATION*FPS)
|
||||
isDiscardData = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// create a matrix to store the image from the cam
|
||||
cv::Mat frame;
|
||||
// wait for a new frame from camera and store it into 'frame'
|
||||
cap.read(frame);
|
||||
// check if we succeeded
|
||||
if (frame.empty())
|
||||
{
|
||||
std::cerr << "[ERROR] blank frame grabbed" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
//Draw Rectangle around the face
|
||||
std::vector<cv::Rect> faceRectangles;
|
||||
faceDetector.detectMultiScale(frame, faceRectangles, 1.1, 3, 0,
|
||||
cv::Size(20, 20));
|
||||
cv::rectangle(frame, faceRectangles[0], cv::Scalar(0, 0, 255), 1, 1, 0);
|
||||
//Reduce to ROI
|
||||
cv::Rect foreheadROI;
|
||||
foreheadROI = faceRectangles[0];
|
||||
foreheadROI.height *= 0.5;
|
||||
|
||||
cv::imshow("Your Face PLS", frame);
|
||||
if (cv::waitKey(1000.0/FPS) >= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue