로그인

검색

Library
2012.10.14 23:31

[OpenCV] 얼굴 인식 예제

MoA
조회 수 1584 추천 수 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 제대로 배우기

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 Tool/etc Programming 게시판 관련 2 MoA 2014.11.01 2838
247 Site 개발에 도움되는 사이트 (초보 개발자 꿀팁) OBG 2023.01.28 187
246 Python FastAPI 톺아보기 - 부제: python 백엔드 봄은 온다 OBG 2023.01.25 172
245 Database 수신 기한이 지난 데이터를 MySQL에서 삭제할 때의 이야기 OBG 2023.01.25 131
244 Tool/etc How To Set Up Multi-Factor Authentication for SSH on Ubuntu 20.04 OBG 2023.01.17 156
243 서버 Caching in Node.js to optimize app performance OBG 2023.01.16 131
242 Web defer, async 스크립트 OBG 2023.01.10 150
241 Tool/etc 쿠버네티스 클러스터 OBG 2022.11.11 162
240 Web 카카오톡 웹버전 만들기 OBG 2022.11.09 282
239 Deeplearning 시계열 데이터 예측 모델 OBG 2022.11.08 156
238 Tool/etc AWS VPC 피어링 OBG 2022.11.03 187
237 Deeplearning The State of AI & Art 2022 1 OBG 2022.10.06 204
236 Deeplearning Stable Diffusion OBG 2022.09.27 188
235 Python 2048 Game in Python OBG 2022.09.22 181
234 Deeplearning Play Super Mario Bros with a Double Deep Q-Network OBG 2022.09.15 157
233 Web Creating A Fixed-Length Queue In JavaScript Using Arrays OBG 2022.09.14 187
232 Deeplearning RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED ... OBG 2022.09.06 228
231 Tool/etc AWS 망 분리하기 OBG 2022.09.06 163
230 Deeplearning Keras를 활용한 주식 가격 예측 OBG 2022.09.02 174
229 Deeplearning 강화학습 학습 관련 정리 OBG 2022.08.10 205
228 Deeplearning 직접 보고 추천하는 머신러닝 & 딥러닝 & 수학 총정리(2022) OBG 2022.07.24 3723
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15