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);
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) 한다.
결과
리본만도 못한 불쌍한 송지은 ㅋㅋㅋ
참고 : Learning OpenCV 제대로 배우기