Haar-cascade Detection 얼굴 검출
OpenCV 2019. 12. 15. 16:34 |It describes how to detect faces with Haar-cascade classifier.
OpenCV에서 Haar-cascade classifier를 이용한 얼굴 검출.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <opencv2/opencv.hpp> using namespace std; using namespace cv; int main() { Mat src = imread("girl.jpg"); if (src.empty()) { cerr << "Image load failed." << endl; return -1; } CascadeClassifier classifier("haarcascade_frontalface_default.xml"); // Cascade classifier class for object detection. if (classifier.empty()) { cerr << "Classifier load failed." << endl; return -1; } vector<Rect> faces; classifier.detectMultiScale(src, faces); // Detects objects of different sizes in the input image. // The detected objects are returned as a list of rectangles. for (Rect rect : faces) { rectangle(src, rect, Scalar(0, 0, 255), 2); } imshow("Face Detection", src); waitKey(0); return 0; } |
Run the program and see the result.
Detected two babies' faces.
It couldn't detect a face with shades and detected some wrong objects.
'OpenCV' 카테고리의 다른 글
OpenCV with Qt and MSVC in Windows (0) | 2021.09.26 |
---|---|
OpenCV with Qt in Linux(Ubuntu) - 리눅스(우분투)에서 Qt로 OpenCV 이미지 디스플레이 (0) | 2021.02.13 |
QR Code detect and decode - QR 코드 리더 (0) | 2019.12.15 |
Simple color detection by Hue - Hue(HSV)값으로 특정색 검출하기 (0) | 2019.11.17 |
Simple copy and save in cv::imshow() 간단하게 이미지 복사, 저장 하기 (0) | 2019.11.17 |