개발환경
사용툴 : Visual Studio 2013 라이브러리 : openCV library 2.4.11 프로젝트 : Visual C++ console application 개발날짜 : 2015-04-08 |
참고 : stackoverflow -OpenCV saving video to file
void FaceDetection::Haar_FaceDetection(const char* filename) { int cnt = 0; //create the cascade classifier object used for the face detection CascadeClassifier face_cascade; //use the haarcascade_frontalface_alt.xml library face_cascade.load("haarcascade_frontalface_alt.xml");
CvCapture* capture;
capture = cvCaptureFromFile(filename); //capture = cvCaptureFromFile("face.jpg");
assert(capture != NULL);
IplImage* bgr_frame;
CvSize size = cvSize((int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH), (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT));
//cvNamedWindow("Webcam", CV_WINDOW_AUTOSIZE);
CvVideoWriter *writer = cvCreateVideoWriter("vp_01003.avi", CV_FOURCC('D', 'I', 'V', 'X'), 15, size);
while ((bgr_frame = cvQueryFrame(capture)) != NULL) { //////////////////////////////////////////////////////////////////////////////////////////// // face detection and process //////////////////////////////////////////////////////////////////////////////////////////// cnt++; //if (cnt == 100) { break; }
Mat f2; Mat frame; //waitKey(10); frame = cvarrToMat(bgr_frame); cvtColor(frame, f2, CV_BGR2GRAY);
equalizeHist(f2, f2);
std::vector<Rect> faces; face_cascade.detectMultiScale(f2, faces, 1.1, 2, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, Size(0, 0), Size(100, 100));
//draw a rectangle for all found faces in the vector array on the original image. for (int i = 0; i < faces.size(); i++) { Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height); Point pt2(faces[i].x, faces[i].y);
rectangle(frame, pt1, pt2, cvScalar(0, 255, 0, 0), 2, 8, 0); printf("face detection! size : %d - %d\n", faces.size(), i); } /////////////////////////////////////////////////////////////////////////////////////////
cvWriteFrame(writer, bgr_frame); cvShowImage("CV_Window", bgr_frame); char c = cvWaitKey(1); if (c == 27) break; printf("A frame processing : %d\n", cnt); }
cvReleaseVideoWriter(&writer); cvReleaseCapture(&capture); cvDestroyWindow("CV_Window"); } |
결과화면
'Computer Vision > Face Detection' 카테고리의 다른 글
[Face Detection] 기술 소개 (0) | 2015.04.17 |
---|---|
[Face Detection] 얼굴인식 알고리즘의 종류와 설명 (0) | 2015.04.16 |
[Face Detection] gpu를 사용한 동영상 얼굴인식 (0) | 2015.04.15 |
[Face Detection] 동영상 얼굴검출 후 모자이크처리 (4) | 2015.04.09 |
[Face Detection] Haar Cascade를 사용한 이미지 얼굴검출 (3) | 2015.04.08 |