You are on page 1of 2

#include "cv.h" #include "highgui.h" #include "wtypes.

h" #include <iostream> static CvMemStorage* storage = 0; static CvHaarClassifierCascade* cascade = 0; CvPoint GetDesktopResolution(); int main() { //baca resolusi CvPoint resolusi=GetDesktopResolution(); printf("resolusi resolusi %d,%d \n",resolusi.x,resolusi.y); //cascade cascade = (CvHaarClassifierCascade*)cvLoad("haarcascade_frontalface_alt. xml", 0, 0, 0); storage = cvCreateMemStorage(0); double scale = 1; //cascade end CvCapture* capture = 0; IplImage *frame, *frame_copy, *gray, *small_img = 0; capture = cvCaptureFromCAM(0); cvNamedWindow("result", 1); if(!cascade)return 0; if (capture) { for(;;) { frame = cvRetrieveFrame(capture); if(!frame) break; frame_copy=cvCloneImage(frame); gray = cvCreateImage( cvSize(frame->width,frame->height) , 8, 1); small_img = cvCreateImage( cvSize( cvRound (frame->width /scale), cvRound (frame->height/scale)), 8, 1 ); cvCvtColor ( frame, gray, CV_BGR2GRAY ); cvResize ( gray, small_img, CV_INTER_LINEAR); cvEqualizeHist ( small_img, small_img); cvClearMemStorage( storage ); if ( cascade ) { CvSeq* faces = cvHaarDetectObjects ( small_img, cascade, storage, 1.1, 2, 0 |CV_HAAR_FIND_BIGGEST_OBJECT //|CV_HAAR_DO_ROUGH_SEARCH //|CV_HAAR_DO_CANNY_PRUNING //|CV_HAAR_SCALE_IMAGE , cvSize(30, 30) ); for (int i = 0; i < (faces ? faces->total : 0); i++) { CvRect* r = (CvRect*)cvGetSeqElem( faces , 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( frame_copy, center, radius, CV _RGB(255,255,255), 3, 8, 0 ); int gbw=frame_copy->width; int gbh=frame_copy->height; int dw=resolusi.x; int dh=resolusi.y; int iw=center.x; int ih=center.y; int posx=(dw/gbw)*iw; int posy=(dh/gbh)*ih; SetCursorPos(center.x,center.y); } cvShowImage("result", frame_copy); if(cvWaitKey(10) >= 0) break; } } } cvReleaseImage (&frame_copy); //cvReleaseImage (&frame); cvReleaseCapture (&capture); cvDestroyWindow ("result"); return 0; } CvPoint GetDesktopResolution() { RECT desktop; const HWND hDesktop = GetDesktopWindow(); GetWindowRect(hDesktop, &desktop); CvPoint out=cvPoint(desktop.right,desktop.bottom); return out; }

You might also like