개발환경
사용툴 : Visual Studio 2013 라이브러리 : openCV library 2.4.10 프로젝트 : Visual C++ console application 개발날짜 : 2015-04-15 |
출처 및 참고 : MARE's Computer Vision Study
void FaceDetection::Usinggpu_FaceDetection(const char* filename) { //load xml file string trainface = "haarcascade_frontalface_alt.xml"; //declaration CascadeClassifier ada_cpu; gpu::CascadeClassifier_GPU ada_gpu; CvCapture* capture; capture = cvCaptureFromFile(filename); assert(capture != NULL);
if (!(ada_cpu.load(trainface))) { printf(" cpu ada xml load fail! \n"); return; } if (!(ada_gpu.load(trainface))) { printf(" gpu ada xml load fail! \n"); return; } IplImage* bgr_frame;
CvSize size = cvSize((int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH), (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT));
cvNamedWindow("CV_Window", 0); cvResizeWindow("CV_Window", 2048, 1024);
while ((bgr_frame = cvQueryFrame(capture)) != NULL) { Mat gray; Mat frame; frame = cvarrToMat(bgr_frame); cvtColor(frame, gray, CV_BGR2GRAY);
equalizeHist(gray, gray);
////////////////////////////////////////////// //cpu case face detection code vector< Rect > faces; ada_cpu.detectMultiScale(gray, faces); if (faces.size() >= 1) { for (int ji = 0; ji < faces.size(); ++ji) { rectangle(frame, faces[ji], CV_RGB(0, 0, 255), CV_FILLED, 4); } } ///////////////////////////////////////////// //gpu case face detection code
gpu::GpuMat faceBuf_gpu; gpu::GpuMat GpuImg; GpuImg.upload(gray); int detectionNumber = ada_gpu.detectMultiScale(GpuImg, faceBuf_gpu); Mat faces_downloaded; if (detectionNumber >= 1) { faceBuf_gpu.colRange(0, detectionNumber).download(faces_downloaded); Rect* faces = faces_downloaded.ptr< Rect>();
for (int ji = 0; ji < detectionNumber; ++ji) { rectangle(frame, Point(faces[ji].x, faces[ji].y), Point(faces[ji].x + faces[ji].width, faces[ji].y + faces[ji].height), CV_RGB(255, 0, 0), 2); } } ///////////////////////////////////////////////// //result display imshow("CV_Window", frame); waitKey(1); } cvReleaseImage(&bgr_frame); //cvReleaseVideoWriter(&writer); cvReleaseCapture(&capture); cvDestroyWindow("CV_Window"); } |
결과화면
얼굴인식 안된 부분은 개인 프라이버시를 위해 별도로 모자이크 처리함.
'Computer Vision > Face Detection' 카테고리의 다른 글
[Face Detection] 기술 소개 (0) | 2015.04.17 |
---|---|
[Face Detection] 얼굴인식 알고리즘의 종류와 설명 (0) | 2015.04.16 |
[Face Detection] 동영상 얼굴검출 후 모자이크처리 (4) | 2015.04.09 |
[Face Detection] Haar Cascade를 사용한 동영상 얼굴검출 (0) | 2015.04.08 |
[Face Detection] Haar Cascade를 사용한 이미지 얼굴검출 (3) | 2015.04.08 |