블로그 이미지
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-27 00:35

Recent Post

Recent Comment

Recent Trackback

Archive

2015. 4. 9. 11:34 Computer Vision/Face Detection



개발환경


사용툴       : Visual Studio 2013

라이브러리 : openCV library 2.4.11

프로젝트    : Visual C++ console application

개발날짜    : 2015-04-09



출처 : Tilltue의 공부방


동영상 얼굴인식 부분http://kanais2.tistory.com/5


cvGet2D 함수 설명 참고 : http://everyone-has-a-blog.tistory.com/92

cvRectangle 함수 설명 참고 : 아몰라님 티스토리

OPENCV Library



Tilltue님의 소스에서 부분적으로 수정 및 추가함.




void FaceDetection::Mosaic_process(IplImage* image, Rect face)

{

     int nCount = 0;

     int mb = 9;

     int w_point = 0, h_point = 0;

     int y_startpoint = 0, x_startpoint = 0;

     double R = 0, G= 0, B = 0;

 

     for (int i = 0 ; i < face.height / mb ; i++) {

             for (int j = 0 ; j < face.width / mb ; j++) {

                   nCount = 0;

                   B = 0; G = 0; R = 0;

 

                    x_startpoint = face.x + (j * mb);

                    y_startpoint = face.y + (i * mb);

                    for (int mb_y = y_startpoint ; mb_y < y_startpoint + mb; mb_y++) {

                          for (int mb_x = x_startpoint ; mb_x < x_startpoint + mb; mb_x++) {

                               CvScalar color;

                                w_point = mb_x;

                                h_point = mb_y;

 

                                if (mb_x >= image->width) {

                                     w_point = image->width - 1;

                                 }

                                 if (mb_y >= image->height){

                                     h_point = image->height - 1;

                                  }

                                  color = cvGet2D(image, h_point, w_point);

                                  B += color.val[0];

                                  G += color.val[1];

                                  R += color.val[2];

                                  nCount++;

                             }

                     }

 

                     //평균을구함

                     B /= nCount;

                     G /= nCount;

                     R /= nCount;

                     CvScalar color;

                     color.val[0] = B;

                     color.val[1] = G;

                     color.val[2] = R;

                     //cvRectangle(image, cvPoint(x_startpoint, y_startpoint), cvPoint(x_startpoint + mb, y_startpoint + mb), cvScalar(0, 0, 0, 0), 1, 8, 0);

                     cvRectangle(image, cvPoint(x_startpoint, y_startpoint), cvPoint(x_startpoint + mb, y_startpoint + mb), color, CV_FILLED, 8, 0);

        }

    }

}





결과화면


- 녹색 테두리되어있는 것만 얼굴인식 후 모자이크 처리된 것임.

- 나머지 모자이크 처리는 제대로 얼굴인식이 되지 않아 임의로 수정한 것.

- 기본 Haar Cascade Classifier 를 사용했다보니 옆얼굴이나 기운얼굴이나 안경낀 얼굴은제대로 인식하지 못함.



posted by Kanais