Detection Tracking

Eden.Yang·2023년 10월 31일
0

Computer VIsion

목록 보기
18/22

CascadeClassifier face_classifier; // cascade 분류기를 위해선 이런 class를 선언해야 한다.

face_classifier.load("haarcascade_frontalface_alt.xml"); //그리고 그 클래스에 xml(data 파일)을 가져온다.

위의 haarcascade_frontalface_alt를 가져오면 정면 얼굴 detection을 가져오게 된다. 검출하고 싶은 것에 따라서 다른 xml파일을 로드하면 된다.


  • Image : Matrix of the type CV_8U containing an image where objects are detected.
  • Objects : Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.
  • numDetections: Vector of detection numbers for the corresponding objects. An object's number of detections is the number of neighboring positively classified rectangles that were joined together to form the object.
  • scaleFactor: Parameter specifying how much the image size is reduced at each image scale.
  • minNeighbors: Parameter specifying how many neighbors each candidate rectangle should have to retain it.
  • flags: Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
  • minSize: Minimum possible object size. Objects smaller than that are ignored.
  • maxSize: Maximum possible object size. Objects larger than that are ignored. If maxSize==minSize, model is evaluated on single scale.

Image (이미지): CV_8U 형식의 매트릭스(matrix)로 표현된 이미지입니다. CV_8U는 8비트 부호 없는 정수를 나타내는 데이터 타입입니다. 이 이미지에는 객체가 감지됩니다.

Objects (객체들): Rectangles의 벡터로 표현됩니다. 각각의 사각형 안에는 감지된 객체가 포함되어 있습니다. 이 때, 사각형은 원본 이미지를 벗어날 수도 있습니다.

numDetections (객체 감지 수): numDetections은 감지된 객체에 대한 감지 번호를 담고 있는 벡터입니다. 여기서 "감지 번호"는 양성으로 분류된 이웃 사각형들이 하나의 객체로 합쳐진 횟수를 나타냅니다.

scaleFactor (이미지 축소 비율): 이미지 크기를 각 스케일에서 얼마나 축소할지를 지정하는 매개변수입니다. 이미지 스케일을 줄일수록 더 작은 객체들도 감지할 수 있습니다.

minNeighbors (이웃 사각형 최소 개수): 각 후보 사각형이 유지되기 위해 가져야 하는 이웃 사각형의 최소 개수를 지정하는 매개변수입니다. 이 값이 높을수록 더 엄격한 필터링이 이루어집니다.

flags (플래그): 이 매개변수는 오래된 캐스케이드(예: Haar 분류기)에서 사용되며, cvHaarDetectObjects 함수에서의 의미와 동일합니다. 새로운 캐스케이드에서는 사용되지 않습니다.

minSize (최소 객체 크기): 무시할 수 있는 최소한의 객체 크기를 지정하는 매개변수입니다. 이 값보다 작은 객체들은 무시됩니다.

maxSize (최대 객체 크기): 무시할 수 있는 최대한의 객체 크기를 지정하는 매개변수입니다. 이 값보다 큰 객체들은 무시됩니다. 만약 maxSize와 minSize가 같다면, 모델은 단일 스케일에서 평가됩니다


Face Detection Example Code

CascadeClassifierface_classifier;
Matframe, grayframe;
vector<Rect> faces;
inti;

// openthewebcam
VideoCapturecap(0);

// checkifwesucceeded
if(!cap.isOpened()) {
	cout<< "Couldnotopencamera" << endl;
	return-1;
}

// facedetectionconfiguration
face_classifier.load("haarcascade_frontalface_alt.xml");

while(true) {
			// getanewframefromwebcam
            cap>> frame;
            
            // convertcapturedframetograyscale
            cvtColor(frame, grayframe, COLOR_BGR2GRAY);

			face_classifier.detectMultiScale(
            				grayframe,
                            faces,
                            1.1, // increasesearchscaleby10% eachpass
                            3,   // mergegroupsof threedetections
                            0,   // notusedforanewcascade
                            Size(30, 30) //minimumsizefor detection
			);
                            
                            // drawtheresults
                            for(i= 0; i< faces.size(); i++) {
                            			Pointlb(faces[i].x+ faces[i].width, faces[i].y+ faces[i].height);
                                        Pointtr(faces[i].x, faces[i].y);
                                        rectangle(frame, lb, tr, Scalar(0, 255, 0), 3, 4, 0);
							}// printtheoutput
                            imshow("FaceDetection", frame);
                            if(waitKey(33) == 27) break;// ESC
}
profile
손끝에서 땅끝으로, 골방에서 열방으로

0개의 댓글