블로그 이미지
Kanais
Researcher & Developer 퍼즐을 완성하려면 퍼즐 조각들을 하나 둘씩 맞춰나가야 한다. 인생의 퍼즐 조각들을 하나 둘씩 맞춰나가다 보면 인생이란 퍼즐도 완성되는 날이 오려나...?

calendar

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

Notice

04-28 02:36

Recent Post

Recent Comment

Recent Trackback

Archive

2015. 4. 8. 11:30 Computer Vision/Face Detection


개발환경


사용툴       : 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");

}




결과화면



posted by Kanais