로그인

검색

Library
2012.10.14 23:31

[OpenCV] 얼굴 인식 예제

MoA
조회 수 3258 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄 첨부

if( m_pImage ) cvReleaseImage( &m_pImage );

m_pImage = cvLoadImage("somePicture.jpg", CV_LOAD_IMAGE_COLOR);
double scale = 1.3;

CvMemStorage* storage = cvCreateMemStorage(0); 

// 영상 준비 
// 
IplImage* gray = cvCreateImage( cvSize(m_pImage->width,m_pImage->height), 8, 1 ); 
IplImage* small_img = cvCreateImage(
cvSize( cvRound(m_pImage->width/scale), cvRound(m_pImage->height/scale)), 8, 1 
); 
cvCvtColor( m_pImage, gray, CV_BGR2GRAY ); 
cvResize( gray, small_img, CV_INTER_LINEAR ); 
cvEqualizeHist( small_img, small_img );

// 객체 검출 
// 
cvClearMemStorage( storage ); 
CvSeq* objects = cvHaarDetectObjects(
small_img, 
m_pCascade, 
storage,
1.1, 
2, 
0  /*CV_HAAR_DO_CANNY_PRUNING*/, 
cvSize(30, 30)
);

// 객체를 찾고 박스를 그린다.
// 
for( int i = 0 ; i < (objects ? objects->total : 0) ; i++ ) 
{
CvRect* r = (CvRect*)cvGetSeqElem( objects, i );
CvPoint center;
int radius;
center.x = cvRound((r->x + r->width*0.5)*scale);
center.y = cvRound((r->y + r->height*0.5)*scale);
radius = cvRound((r->width + r->height)*0.25*scale);
cvCircle( m_pImage, center, radius, cvScalar(255, 0, 0), 3, 8, 0 );


cvReleaseImage( &gray ); 
cvReleaseImage( &small_img ); 
cvReleaseMemStorage( &storage );

Invalidate(FALSE);

 

위 소스를 적당히 이용하여 새로운 창으로 이미지를 띄우든 (cvNameWindow()) static control에 띄우든(CvvImage class) 한다.

 

결과

 

FaceDetect - Secret.png

 

리본만도 못한 불쌍한 송지은 ㅋㅋㅋ

 

참고 : Learning OpenCV 제대로 배우기

?

  1. Programming 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views11112
    read more
  2. CSpreadSheet

    Date2014.02.03 CategoryLibrary ByMoA Views2226
    Read More
  3. AS3 Code Library

    Date2013.10.11 CategoryLibrary ByMoA Views6451
    Read More
  4. ChartFX 7.0 MFC에서 사용하기

    Date2013.07.28 CategoryLibrary ByMoA Views2651
    Read More
  5. pthread

    Date2013.07.28 CategoryLibrary ByMoA Views1963
    Read More
  6. High-speed Charting Control

    Date2013.07.28 CategoryLibrary ByMoA Views2262
    Read More
  7. [OpenCV] 얼굴 인식 예제

    Date2012.10.14 CategoryLibrary ByMoA Views3258
    Read More
  8. ExcelFormat Library

    Date2012.08.02 CategoryLibrary ByNaya Views3068
    Read More
  9. Google의 C++ 라이브러리

    Date2012.08.02 CategoryLibrary ByNaya Views2370
    Read More
  10. Math Library

    Date2012.08.02 CategoryLibrary ByNaya Views2326
    Read More
  11. Win32 Socket Class

    Date2012.08.02 CategoryLibrary ByNaya Views2888
    Read More
Board Pagination Prev 1 Next
/ 1