-
얼굴 인식 코드컴공지식/컴퓨터비전 2024. 10. 28. 22:20
OpenCV를 이용한 얼굴 인식 코드
웹캠을 사용해서 실시간으로 얼굴을 인식해 준다.
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
CascadeClassifier face_classifier;
Mat frame, grayframe;
vector<Rect> faces;
VideoCapture cap(0);
if (!cap.isOpened()) {
cout << "Could not open camera" << endl;
return -1;
}
face_classifier.load("haarcascade_frontalface_alt.xml");
while (true) {
cap >> frame;
cvtColor(frame, grayframe, COLOR_BGR2GRAY);
face_classifier.detectMultiScale(
grayframe, faces, 1.1, 3, 0, Size(30, 30)
);
for (int i = 0; i < faces.size(); i++) {
Point lb(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
Point tr(faces[i].x, faces[i].y);
rectangle(frame, lb, tr, Scalar(0, 255, 0), 3, 4, 0);
}
imshow("Face Detection", frame);
if (waitKey(33) == 27) break; // ESC 키로 종료
}
return 0;
}'컴공지식 > 컴퓨터비전' 카테고리의 다른 글
Optical Flow (광류 추적) 코드 (1) 2024.10.28 추적 (Tracking) 코드 (1) 2024.10.28 Tracking(추적)이란? (2) 2024.10.28 Face Detection (2) 2024.10.28 객체 탐지 방법 (1) 2024.10.28