/** @function main */ int main( int argc, const char** argv ) { // check arguements // if(argc < 2) // { // printf("ERROR: Please enter window position x & y\n"); // exit(0); // } // // int windowX = atoi(argv[1]); // usually 5 // int windowY = atoi(argv[2]); // usually 14 int windowX = 1274; // usually 5 int windowY = 280; // usually 14 CvCapture* capture; IplImage* frame; FaceTracker* faceTracker = new FaceTracker("/opt/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"); capture = cvCaptureFromCAM(2); if(capture) { cvNamedWindow ("img", CV_WINDOW_AUTOSIZE); cvMoveWindow("img", windowX, windowY); //Set the background to black image = cvLoadImage( "../../data/grandTetons_very_small.jpg", CV_LOAD_IMAGE_UNCHANGED) ; //background = cvCreateImage(cvSize(1024, 768),image->depth,image->nChannels); background = cvCreateImage(cvSize(resX, resY),image->depth,image->nChannels); bgMax = Point(0,0); bgMax = Point(background->width-1,background->height-1); cvRectangle(background, Point(0,0), Point(background->width,background->height), cvScalar(0, 0, 0), CV_FILLED, 8, 0); setupParticles(); Face face; face.x = background->width/2; face.y = background->height/2; face.radius = 1; while( true ) { frame = cvQueryFrame( capture ); faceTracker->findFace(frame); if (faceTracker->numFaces) { // scale face position in relation to background width int xPerc = frame->width - faceTracker->face.x; // invert to flip xPerc = (float)xPerc * ((float)image->width/(float)frame->width); xPerc += xOffset; int yPerc = faceTracker->face.y; yPerc = (float)yPerc * ((float)image->height/(float)frame->height); yPerc += yOffset; int rPerc = faceTracker->face.radius; // scale face position in relation to background width rPerc = (float)rPerc * ((float)image->width/(float)frame->width); //printf("x %d y %d r %d\n", xPerc, yPerc, rPerc); face.x = xPerc; face.y = yPerc; face.radius = rPerc; face.radius *= 1.8; cvRectangle(background, Point(0,0), Point(background->width,background->height), cvScalar(0, 0, 0), CV_FILLED, 8, 0); update(&face); // put video behind image cvFlip(frame, NULL, 1); // flip image so it mirrors the user cvSetImageROI(background, cvRect(xOffset, yOffset, image->width-1, image->height)); cvResize(frame, background, CV_INTER_LINEAR); cvResetImageROI(background); } else { face.x = 0; face.y = 0; face.radius = 1; cvRectangle(background, Point(0,0), Point(background->width,background->height), cvScalar(0, 0, 0), CV_FILLED, 8, 0); update(&face); } draw(background); cvShowImage("img", background); int c = waitKey(1); switch (c) { case 'c': case 'C': cursorMode = ( cursorMode + 1 > 1 ) ? 0 : 1 ; break ; case 's': case 'S': springEnabled = !springEnabled ; break ; case 'r': case 'R': reset(); break ; } //cvReleaseImage(&frame); } } else{ printf("ERROR: Camera not loaded\n"); } return 0; }