Created
March 23, 2014 07:18
-
-
Save ser1zw/9719848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "opencv2/objdetect/objdetect.hpp" | |
#include "opencv2/highgui/highgui.hpp" | |
#include "opencv2/imgproc/imgproc.hpp" | |
int main(int argc, char *argv[]) { | |
cv::String faceCascadeFileName = "./cascade.xml"; | |
cv::String windowName = "Face detection"; | |
cv::String imageFileName = "./lenna.png"; | |
cv::CascadeClassifier faceCascade; | |
cv::Mat face; | |
cv::Mat faceGray; | |
std::vector<cv::Rect> faceRects; | |
if (!faceCascade.load(faceCascadeFileName)) { | |
return -1; | |
} | |
face = cv::imread(imageFileName, 1); | |
if (face.empty()) { | |
return -1; | |
} | |
cv::cvtColor(face, faceGray, cv::COLOR_BGR2GRAY); | |
cv::equalizeHist(faceGray, faceGray); | |
faceCascade.detectMultiScale(faceGray, faceRects, 1.1, 2, 0 | cv::CASCADE_SCALE_IMAGE, cv::Size(30, 30)); | |
for (size_t i = 0; i < faceRects.size(); i++) { | |
cv::Point center(faceRects[i].x + faceRects[i].width / 2, faceRects[i].y + faceRects[i].height / 2); | |
cv::ellipse(face, center, cv::Size(faceRects[i].width / 2, faceRects[i].height / 2), 0, 0, 360, cv::Scalar(255, 0, 255), 4, 8, 0); | |
} | |
cv::imshow(windowName, face); | |
cv::waitKey(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment