/// Makes a button and its four different state bitmaps /// @param eUp Background for when button is Up. /// @param eDown Background for when button is Down. /// @param eHilite Background for when button is Hilit. /// @param eStandardUp Foreground when enabled, up. /// @param eStandardDown Foregrounde when enabled, down. /// @param eDisabled Foreground when disabled. /// @param id Windows Id. /// @param placement Placement position /// @param processdownevents true iff button handles down events. /// @param size Size of the background. AButton * ToolBar::MakeButton(teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size) { int xoff = (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2; int yoff = (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2; typedef std::unique_ptr<wxImage> wxImagePtr; wxImagePtr up2 (OverlayImage(eUp, eStandardUp, xoff, yoff)); wxImagePtr hilite2 (OverlayImage(eHilite, eStandardUp, xoff, yoff)); wxImagePtr down2 (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1)); wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff)); AButton * button = new AButton(this, id, placement, size, *up2, *hilite2, *down2, *disable2, processdownevents); return button; }
/// Makes a button and its four different state bitmaps /// @param eUp Background for when button is Up. /// @param eDown Background for when button is Down. /// @param eHilite Background for when button is Hilit. /// @param eStandard Foreground when enabled. /// @param eDisabled Foreground when disabled. /// @param id Windows Id. /// @param placement Placement position /// @param processdownevents true iff button handles down events. /// @param size Size of the background. AButton * ToolBar::MakeButton(teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eStandard, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size) { int xoff = (size.GetWidth() - theTheme.Image(eStandard).GetWidth())/2; int yoff = (size.GetHeight() - theTheme.Image(eStandard).GetHeight())/2; wxImage * up2 = OverlayImage(eUp, eStandard, xoff, yoff); wxImage * hilite2 = OverlayImage(eHilite, eStandard, xoff, yoff); wxImage * down2 = OverlayImage(eDown, eStandard, xoff + 1, yoff + 1); wxImage * disable2 = OverlayImage(eUp, eDisabled, xoff, yoff); AButton * button = new AButton(this, id, placement, size, *up2, *hilite2, *down2, *disable2, processdownevents); delete up2; delete down2; delete hilite2; delete disable2; return button; }
///This is a generic function that will make a button, given ///generic button images. /// Parameters: /// /// up: An image of the blank button in its "up" state /// down: An image of the blank button in its "down" state /// hilite An image of the blank button with the hilite halo /// foreground: A color bitmap of the icon on the button when its /// enabled--Can be a solid field. /// disabledfg: A color bitmap of the icon when its disabled--can be a solid field. /// alpha: A greyscale mask that determines how much of the /// foreground shows through /// id Button ID /// placement Location on the toolbar /// processdownevents boolean that determine whether the button will process events /// if it is in the down position (and pop up when clicked in the down position) /// xoff x-offset to place icon pixmaps at, with respect to background image /// yoff y-offset to place icon pixmaps at, with respect to background image AButton * ToolBar::MakeButton(wxImage * up, wxImage * down, wxImage * hilite, const char **foreground, const char **disabledfg, const char **alpha, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size, int xoff, int yoff) { wxImage * color = new wxImage(wxBitmap(foreground).ConvertToImage()); wxImage * color_disabled = new wxImage(wxBitmap(disabledfg).ConvertToImage()); wxImage * mask = new wxImage(wxBitmap(alpha).ConvertToImage()); wxImage * up2 = OverlayImage(up, color, mask, xoff, yoff); wxImage * hilite2 = OverlayImage(hilite, color, mask, xoff, yoff); wxImage * down2 = OverlayImage(down, color, mask, xoff + 1, yoff + 1); wxImage * disable2 = OverlayImage(up, color_disabled, mask, xoff, yoff); AButton * button = new AButton(this, id, placement, size, up2, hilite2, down2, disable2, processdownevents); delete color; delete color_disabled; delete mask; delete up2; delete down2; delete hilite2; delete disable2; return button; }
wxImage *ControlToolBar::MakeToolImage(wxImage * tool, wxImage * mask, int style) { // This code takes the image of a tool, and its mask, // and creates one of four images of this tool inside // a little button, for the toolbar. The tool // is alpha-blended onto the background. const char **src; switch(style) { case 1: // hilite src = Hilite; break; case 2: // down src = Down; break; default: src = Up; break; } wxImage *bkgndOriginal = new wxImage(wxBitmap(src).ConvertToImage()); wxImage *upOriginal = new wxImage(wxBitmap(Up).ConvertToImage()); #ifdef __WXMAC__ wxImage *background = bkgndOriginal; #else wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); wxColour baseColour; unsigned char *data = upOriginal->GetData(); baseColour.Set(data[28 * 3], data[28 * 3 + 1], data[28 * 3 + 2]); wxImage *background = ChangeImageColour(bkgndOriginal, baseColour, backgroundColour); #endif // // Overlay the tool on top of it // wxImage *result; if (style == 2) // down result = OverlayImage(background, tool, mask, 1, 1); else result = OverlayImage(background, tool, mask, 0, 0); delete background; #ifndef __WXMAC__ delete bkgndOriginal; delete upOriginal; #endif return result; }
///This is a generic function that will make a button, given ///generic button images. /// Parameters: /// /// up: An image of the blank button in its "up" state /// down: An image of the blank button in its "down" state /// hilite An image of the blank button with the hilite halo /// foreground: A color bitmap of the icon on the button when its /// enabled--Can be a solid field. /// disabledfg: A color bitmap of the icon when its disabled--can be a solid field. /// alpha: A greyscale mask that determines how much of the /// foreground shows through /// id Button ID /// placement Location on the toolbar /// processdownevents boolean that determine whether the button will process events /// if it is in the down position (and pop up when clicked in the down position) /// xadjust x-offset to adjust the icon pixmaps from, wrt a centered icon on background image /// yadjust y-offset to adjust the icon pixmaps from, wrt a centered icon on background image AButton * ToolBar::MakeButton(wxImage * up, wxImage * down, wxImage * hilite, const char **foreground, const char **disabledfg, const char **alpha, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size, int xadjust, int yadjust) { wxImage * color = new wxImage(wxBitmap(foreground).ConvertToImage()); wxImage * color_disabled = new wxImage(wxBitmap(disabledfg).ConvertToImage()); wxImage * mask = new wxImage(wxBitmap(alpha).ConvertToImage()); //Some images need to be centered on the button. We calculate the centered values here, and then //adjust by xoff/yoff, for maximum control. int xoff = (size.GetWidth() - color->GetWidth())/2 + xadjust; int yoff = (size.GetHeight() - color->GetHeight())/2 + yadjust; wxImage * up2 = OverlayImage(up, color, mask, xoff, yoff); wxImage * hilite2 = OverlayImage(hilite, color, mask, xoff, yoff); wxImage * down2 = OverlayImage(down, color, mask, xoff + 1, yoff + 1); wxImage * disable2 = OverlayImage(up, color_disabled, mask, xoff, yoff); AButton * button = new AButton(this, id, placement, size, up2, hilite2, down2, disable2, processdownevents); delete color; delete color_disabled; delete mask; delete up2; delete down2; delete hilite2; delete disable2; return button; }
//static void ToolBar::MakeAlternateImages(AButton &button, int idx, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxSize size) { int xoff = (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2; int yoff = (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2; typedef std::unique_ptr<wxImage> wxImagePtr; wxImagePtr up (OverlayImage(eUp, eStandardUp, xoff, yoff)); wxImagePtr hilite (OverlayImage(eHilite, eStandardUp, xoff, yoff)); wxImagePtr down (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1)); wxImagePtr disable (OverlayImage(eUp, eDisabled, xoff, yoff)); button.SetAlternateImages(idx, *up, *hilite, *down, *disable); }
void ControlToolBar::MakeLoopImage() { // JKC: See ToolBar::MakeButton() for almost identical code. Condense?? wxSize Size1( theTheme.ImageSize( bmpRecoloredUpLarge )); wxSize Size2( theTheme.ImageSize( bmpLoop )); int xoff = (Size1.GetWidth() - Size2.GetWidth())/2; int yoff = (Size1.GetHeight() - Size2.GetHeight())/2; wxImage * up2 = OverlayImage(bmpRecoloredUpLarge, bmpLoop, xoff, yoff); wxImage * hilite2 = OverlayImage(bmpRecoloredHiliteLarge, bmpLoop, xoff, yoff); wxImage * down2 = OverlayImage(bmpRecoloredDownLarge, bmpLoop, xoff + 1, yoff + 1); wxImage * disable2 = OverlayImage(bmpRecoloredUpLarge, bmpLoopDisabled, xoff, yoff); mPlay->SetAlternateImages(*up2, *hilite2, *down2, *disable2); delete up2; delete hilite2; delete down2; delete disable2; }
void ControlToolBar::MakeLoopImage() { int xoff = 16; int yoff = 16; wxImage * color = new wxImage(wxBitmap(Loop).ConvertToImage()); wxImage * color_disabled = new wxImage(wxBitmap(LoopDisabled).ConvertToImage()); wxImage * mask = new wxImage(wxBitmap(LoopAlpha).ConvertToImage()); wxImage * up2 = OverlayImage(upPattern, color, mask, xoff, yoff); wxImage * hilite2 = OverlayImage(hilitePattern, color, mask, xoff, yoff); wxImage * down2 = OverlayImage(downPattern, color, mask, xoff + 1, yoff + 1); wxImage * disable2 = OverlayImage(upPattern, color_disabled, mask, xoff, yoff); mPlay->SetAlternateImages(up2, hilite2, down2, disable2); delete color; delete color_disabled; delete mask; delete up2; delete hilite2; delete down2; delete disable2; }
int main( int argc, char** argv ) { contadorBlue = 0; contadorGreen = 0; contadorRed = 0; CvCapture *capture = NULL; IplImage *frame = NULL; IplImage *result = NULL; int key; char *filename = (char*)"aGest.xml"; /* load the classifier note that I put the file in the same directory with this code */ cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 ); /* setup memory buffer; needed by the face detector */ storage = cvCreateMemStorage( 0 ); /* initialize camera */ capture = cvCaptureFromCAM( 0 ); /* always check */ assert( cascade && storage && capture ); /* open and rezise images to be overlayed */ IplImage *drumblue = cvLoadImage("./Drums/DrumBlue.png"); IplImage *drumgreen = cvLoadImage("./Drums/DrumGreen.png"); IplImage *drumred = cvLoadImage("./Drums/DrumRed.png"); IplImage *lineblue = cvLoadImage("./Drums/BlueLine.png"); IplImage *linegreen = cvLoadImage("./Drums/GreenLine.png"); IplImage *linered = cvLoadImage("./Drums/RedLine.png"); IplImage *step1 = cvLoadImage("./Drums/Step.png"); IplImage *step2 = cvLoadImage("./Drums/Step2.png"); IplImage *arrow1 = cvLoadImage("./Drums/Arrow1.png"); IplImage *arrow2 = cvLoadImage("./Drums/Arrow2.png"); IplImage *bien = cvLoadImage("./Drums/Bien.png"); IplImage *buu = cvLoadImage("./Drums/Buu.png"); IplImage *rdrumblue = cvCreateImage(cvSize(110,95),drumblue->depth, drumblue->nChannels); IplImage *rdrumgreen = cvCreateImage(cvSize(110,95),drumgreen->depth, drumgreen->nChannels); IplImage *rdrumred = cvCreateImage(cvSize(110,95),drumred->depth, drumred->nChannels); IplImage *rdrumblue2 = cvCreateImage(cvSize(110,95),drumblue->depth, drumblue->nChannels); IplImage *rdrumgreen2 = cvCreateImage(cvSize(110,95),drumgreen->depth, drumgreen->nChannels); IplImage *rdrumred2 = cvCreateImage(cvSize(110,95),drumred->depth, drumred->nChannels); IplImage *rlineblue = cvCreateImage(cvSize(230,80),lineblue->depth, lineblue->nChannels); IplImage *rlinegreen = cvCreateImage(cvSize(230,80),linegreen->depth, linegreen->nChannels); IplImage *rlinered = cvCreateImage(cvSize(230,80),linered->depth, linered->nChannels); IplImage *rlineblue2 = cvCreateImage(cvSize(230,80),lineblue->depth, lineblue->nChannels); IplImage *rlinegreen2 = cvCreateImage(cvSize(230,80),linegreen->depth, linegreen->nChannels); IplImage *rlinered2 = cvCreateImage(cvSize(230,80),linered->depth, linered->nChannels); IplImage *rstep1 = cvCreateImage(cvSize(100,100),step1->depth, step1->nChannels); IplImage *rstep2 = cvCreateImage(cvSize(100,100),step2->depth, step2->nChannels); IplImage *rarrow1 = cvCreateImage(cvSize(110,70),arrow1->depth, arrow1->nChannels); IplImage *rarrow2 = cvCreateImage(cvSize(110,70),arrow2->depth, arrow2->nChannels); IplImage *rbien = cvCreateImage(cvSize(60,25),bien->depth, bien->nChannels); IplImage *rbuu = cvCreateImage(cvSize(60,25),buu->depth, buu->nChannels); cvResize(drumblue, rdrumblue); cvResize(drumgreen, rdrumgreen); cvResize(drumred, rdrumred); cvResize(drumblue, rdrumblue2); cvResize(drumgreen, rdrumgreen2); cvResize(drumred, rdrumred2); cvResize(lineblue, rlineblue); cvResize(linegreen, rlinegreen); cvResize(linered, rlinered); cvResize(lineblue, rlineblue2); cvResize(linegreen, rlinegreen2); cvResize(linered, rlinered2); cvResize(step1, rstep1); cvResize(step2, rstep2); cvResize(arrow1, rarrow1); cvResize(arrow2, rarrow2); cvResize(bien, rbien); cvResize(buu, rbuu); cvFlip(rdrumblue2, rdrumblue2,1); cvFlip(rdrumgreen2, rdrumgreen2,1); cvFlip(rdrumred2, rdrumred2,1); cvFlip(rlineblue2, rlineblue2,1); cvFlip(rlinegreen2, rlinegreen2,1); cvFlip(rlinered2, rlinered2,1); /* release memory */ cvReleaseImage( &drumblue); cvReleaseImage( &drumgreen); cvReleaseImage( &drumred); cvReleaseImage( &lineblue); cvReleaseImage( &linegreen); cvReleaseImage( &linered ); cvReleaseImage( &step1 ); cvReleaseImage( &step2 ); cvReleaseImage( &arrow1 ); cvReleaseImage( &arrow2 ); cvReleaseImage( &bien); cvReleaseImage( &buu); /* create a window */ cvNamedWindow( "video", 1 ); /* set time and frame variables*/ initGame = clock (); frameN = 0; /* set scores*/ score1 = 0; score2 = 0; redb = false; greenb = false; blueb = false; redb2 = false; greenb2 = false; blueb2 = false; bienn =0; maln =0; std::list<int> lista; lista.push_front(1); lista.push_front(2); lista.push_front(3); lista.push_front(4); lista.push_front(5); while( key != 'q' ) { /* get a frame */ //frame: 640,480 frame = cvQueryFrame( capture ); /* always check */ if( !frame ) break; /* clone and 'fix' frame */ cvFlip( frame, frame, 1 ); GenerateScoreMessage(frame,score1,score2); /* detect Hands and draw boxes */ detectHands( frame, rlineblue2, rlinegreen2, rlinered2, false ); detectHands( frame, rlineblue, rlinegreen, rlinered, true); /* overlay the game play buttons */ cvLine(frame, cvPoint(320,0), cvPoint(320,480), cvScalar(255,255,0), 2); OverlayImage(frame,rdrumblue,cvPoint(0,240),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rdrumgreen,cvPoint(0,315),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rdrumred,cvPoint(0,390),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rdrumblue2,cvPoint(530, 15),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rdrumgreen2,cvPoint(530,90),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rdrumred2,cvPoint(530,165),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rarrow1,cvPoint(0, 23),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rarrow1,cvPoint(0,98),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rarrow1,cvPoint(0,173),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rarrow2,cvPoint(530,248),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rarrow2,cvPoint(530,323),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); OverlayImage(frame,rarrow2,cvPoint(530,398),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); drawAndAdvance(frame,rbien, rbuu, rstep1, rstep2 ); // OverlayImage(frame,rstep1,cvPoint(200,330),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); // OverlayImage(frame,rstep2,cvPoint(400,330),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); // OverlayImage(frame,rbien,cvPoint(200,200),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); // OverlayImage(frame,rbuu,cvPoint(400,200),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); /* display video */ cvShowImage( "video", frame ); /* quit if user press 'q' */ key = cvWaitKey( 10 ); frameN++; } /* free memory */ cvReleaseCapture( &capture ); cvDestroyWindow( "video" ); cvReleaseHaarClassifierCascade( &cascade ); cvReleaseMemStorage( &storage ); return 0; }
void drawAndAdvance(IplImage *src,IplImage *good, IplImage *bad, IplImage *rstep1, IplImage *rstep2 ){ for (std::list<paso>::iterator it=pasos1.begin(); it!=pasos1.end(); ++it){ //dibujar if ((*it).tipo == 0) OverlayImage(src,rstep1,cvPoint((*it).pos, 20),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); if ((*it).tipo == 1) OverlayImage(src,rstep1,cvPoint((*it).pos, 95),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); if ((*it).tipo == 2) OverlayImage(src,rstep1,cvPoint((*it).pos, 170),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); //si llego al otro lado if ((*it).tipo == 0 && (*it).pos>560 && (*it).pos<595 ){ if (blueb2){ score2 += 1; //drawBien(src,good,0,0); pasos1.erase(it); } } else if ((*it).tipo == 1 && (*it).pos>560 && (*it).pos<595 ){ if (greenb2){ score2 += 1; //drawBien(src,good,1,0); pasos1.erase(it); } } else if ((*it).tipo == 2 && (*it).pos>560 && (*it).pos<595 ){ if (redb2){ score2 += 1; //drawBien(src,good,2,0); pasos1.erase(it); } } // si no se acerto el tambor if ((*it).tipo == 0 && (*it).pos>600 ){ score2 -= 1; //drawBien(src,bad,0,0); pasos1.erase(it); } else if ((*it).tipo == 1 && (*it).pos>600 ){ score2 -= 1; //drawBien(src,bad,1,0); pasos1.erase(it); } else if ((*it).tipo == 1 && (*it).pos>600){ score2 -= 1; //drawBien(src,bad,2,0); pasos1.erase(it); } (*it).pos +=4; } for (std::list<paso>::iterator it=pasos2.begin(); it!=pasos2.end(); ++it){ //dibujar if ((*it).tipo == 0) OverlayImage(src,rstep2,cvPoint((*it).pos, 245),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); if ((*it).tipo == 1) OverlayImage(src,rstep2,cvPoint((*it).pos, 320),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); if ((*it).tipo == 2) OverlayImage(src,rstep2,cvPoint((*it).pos, 395),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); //si llego al otro lado if ((*it).tipo == 0 && (*it).pos>30 && (*it).pos<65 ){ if (blueb){ score1 += 1; //drawBien(src,good,0,0); pasos2.erase(it); } } else if ((*it).tipo == 1 && (*it).pos>30 && (*it).pos<65 ){ if (greenb){ score1 += 1; //drawBien(src,good,1,0); pasos2.erase(it); } } else if ((*it).tipo == 2 && (*it).pos>30 && (*it).pos<65 ){ if (redb){ score1 += 1; //drawBien(src,good,2,0); pasos2.erase(it); } } // si no se acerto el tambor if ((*it).tipo == 0 && (*it).pos<25 ){ score1 -= 1; //drawBien(src,bad,0,0); pasos2.erase(it); } else if ((*it).tipo == 1 && (*it).pos<25 ){ score1 -= 1; //drawBien(src,bad,1,0); pasos2.erase(it); } else if ((*it).tipo == 1 && (*it).pos<25){ score1 -= 1; //drawBien(src,bad,2,0); pasos2.erase(it); } (*it).pos -=4; } }
void CheckAndDraw(IplImage *img, CvRect *rect, IplImage *blue, IplImage *green, IplImage *red, bool caso){ //calcular punto medio de la mano int x = rect->x + (rect->width)/2; int y = rect->y + (rect->height)/2; bool check = true; bool check2 = true; paso step; if (caso){ //tocar azul if (x>30 && x<65 && y>265 && y<295){ contadorBlue = 0; contadorGreen++; contadorRed++; check = false; } //tocar verde if (x>30 && x<65 && y>340 && y<370){ contadorGreen = 0; contadorBlue++; contadorRed++; check = false; } //tocar rojo if (x>30 && x<65 && y>415 && y< 445){ contadorRed = 0; contadorBlue++; contadorGreen++; check = false; } //no tocas nada if (check) { contadorBlue++; contadorGreen++; contadorRed++; } check = true; //tocar arriba if (x>30 && x<65 && y>40 && y<70){ contadorArriba = 0; contadorMedio++; contadorAbajo++; check = false; } //tocar medio if (x>30 && x<65 && y>115 && y<145){ contadorMedio = 0; contadorArriba++; contadorAbajo++; check = false; } //tocar abajo if (x>30 && x<65 && y>190 && y< 220){ contadorAbajo = 0; contadorMedio++; contadorArriba++; check = false; } //no tocas nada if (check) { contadorArriba++; contadorMedio++; contadorAbajo++; } if (contadorBlue<10){ OverlayImage(img,blue,cvPoint(100, 240),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); blueb = true; } else blueb = false; if(contadorRed<10){ OverlayImage(img,red,cvPoint(100,395),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); redb = true; } else redb = false; if(contadorGreen<10){ OverlayImage(img,green,cvPoint(100,320),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); greenb = true; } else greenb = false; if (contadorArriba<10){ step.pos = 100; step.tipo = 0; step.frame = frameN; if (!pasos1.empty()){ if ( frameN - pasos1.front().frame > 30) pasos1.push_front(step); } else { pasos1.push_front(step); } } if(contadorMedio<10){ step.pos = 100; step.tipo = 1; step.frame = frameN; if (!pasos1.empty()){ if ( frameN - pasos1.front().frame > 30) pasos1.push_front(step); } else { pasos1.push_front(step); } } if(contadorAbajo<10){ step.pos = 100; step.tipo = 2; step.frame = frameN; if (!pasos1.empty()){ if ( frameN - pasos1.front().frame > 30) pasos1.push_front(step); } else { pasos1.push_front(step); } } } else{ //tocar azul if (x>560 && x<595 && y>40 && y<70){ contadorBlue2 = 0; contadorGreen2++; contadorRed2++; check2 = false; } //tocar verde if (x>560 && x<595 && y>115 && y<145){ contadorGreen2 = 0; contadorBlue2++; contadorRed2++; check2 = false; } //tocar rojo if (x>560 && x<595 && y>190 && y< 220){ contadorRed2 = 0; contadorBlue2++; contadorGreen2++; check2 = false; } //no tocas nada if (check2) { contadorBlue2++; contadorGreen2++; contadorRed2++; } check2 = true; //tocar arriba if (x>560 && x<595 && y>265 && y<295){ contadorArriba2 = 0; contadorMedio2++; contadorAbajo2++; check2 = false; } //tocar medio if (x>560 && x<595 && y>340 && y<370){ contadorMedio2 = 0; contadorArriba2++; contadorAbajo2++; check2 = false; } //tocar abajo if (x>560 && x<595 && y>415 && y< 445){ contadorAbajo2 = 0; contadorMedio2++; contadorArriba2++; check2 = false; } //no tocas nada if (check2) { contadorArriba2++; contadorMedio2++; contadorAbajo2++; } if (contadorBlue2<10){ OverlayImage(img,blue,cvPoint(345, 20),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); blueb2 = true; } else blueb2 = false; if(contadorRed2<10){ OverlayImage(img,red,cvPoint(345,170),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); redb2 = true; } else redb2 = false; if(contadorGreen2<10){ OverlayImage(img,green,cvPoint(345,95),cvScalar(1,1,1,1),cvScalar(1,1,1,1)); greenb2 = true; } else greenb2 = false; if (contadorArriba2<10){ step.pos = 500; step.tipo = 0; step.frame = frameN; if (!pasos2.empty()){ if ( frameN - pasos2.front().frame > 30) pasos2.push_front(step); } else { pasos2.push_front(step); } } if(contadorMedio2<10){ step.pos = 500; step.tipo = 1; step.frame = frameN; if (!pasos2.empty()){ if ( frameN - pasos2.front().frame > 30) pasos2.push_front(step); } else { pasos2.push_front(step); } } if(contadorAbajo2<10){ step.pos = 500; step.tipo = 2; step.frame = frameN; if (!pasos2.empty()){ if ( frameN - pasos2.front().frame > 30) pasos2.push_front(step); } else { pasos2.push_front(step); } } } }
AButton * ToolBar::MakeButton(wxImage * up, wxImage * down, wxImage * hilite, const char **foreground, const char **disabledfg, const char **alpha, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size, int xoff, int yoff) { //This is a generic function that will make a button, given //generic button images. // Parameters: // // up: An image of the blank button in its "up" state // down: An image of the blank button in its "down" state // hilite An image of the blank button with the hilite halo // foreground: A color bitmap of the icon on the button when its // enabled--Can be a solid field. // disabledfg: A color bitmap of the icon when its disabled--can be a solid field. // alpha: A greyscale mask that determines how much of the // foreground shows through // id Button ID // placement Location on the toolbar // processdownevents boolean that determine whether the button will process events // if it is in the down position (and pop up when clicked in the down position) // xoff x-offset to place icon pixmaps at, with respect to background image // yoff y-offset to place icon pixmaps at, with respect to background image #if wxVERSION_NUMBER < 2303 wxImage * color = new wxImage(wxBitmap(foreground)); wxImage * color_disabled = new wxImage(wxBitmap(disabledfg)); wxImage * mask = new wxImage(wxBitmap(alpha)); wxImage * up2 = OverlayImage(up, color, mask, xoff, yoff); wxImage * hilite2 = OverlayImage(hilite, color, mask, xoff, yoff); wxImage * down2 = OverlayImage(down, color, mask, xoff + 1, yoff + 1); wxImage * disable2 = OverlayImage(up, color_disabled, mask, xoff, yoff); #else wxImage * color = new wxImage(wxBitmap(foreground).ConvertToImage()); wxImage * color_disabled = new wxImage(wxBitmap(disabledfg).ConvertToImage()); wxImage * mask = new wxImage(wxBitmap(alpha).ConvertToImage()); wxImage * up2 = OverlayImage(up, color, mask, xoff, yoff); wxImage * hilite2 = OverlayImage(hilite, color, mask, xoff, yoff); wxImage * down2 = OverlayImage(down, color, mask, xoff + 1, yoff + 1); wxImage * disable2 = OverlayImage(up, color_disabled, mask, xoff, yoff); #endif AButton * button = new AButton(this, id, placement, size, up2, hilite2, down2, disable2, processdownevents); delete color; delete color_disabled; delete mask; delete up2; delete down2; delete hilite2; delete disable2; return button; }
Mat HUD(Mat videoFeed, int sizex, int sizey) { // Read HUD image Mat image; if (gameOn && !peoplePicked && !cratePicked) image = imread("..\\..\\src\\resource\\hudg.png", -1); else if (gameOn && !peoplePicked && cratePicked) image = imread("..\\..\\src\\resource\\hudc.png", -1); else if (gameOn && peoplePicked && !cratePicked) image = imread("..\\..\\src\\resource\\hudp.png", -1); else if (gameOn && peoplePicked && cratePicked) image = imread("..\\..\\src\\resource\\hudpc.png", -1); else image = imread("..\\..\\src\\resource\\hud.png", -1); // Create a buffer of the image Mat buffer; videoFeed.copyTo(buffer); // Resized HUD image Mat rImage; // Resize HUD to fit window resize(image, rImage, Size(sizex, sizey), 0, 0, INTER_CUBIC); // Create a matrix to mix the video feed with the HUD image Mat result; // Overlay the HUD over the video feed OverlayImage(videoFeed, rImage, result, Point(0, 0)); // Draw the crosshair Point2f point(sizex / 2, sizey / 2); circle(buffer, point, 10, Scalar(255, 255, 0), -1); // Display info on to HUD ostringstream str; // string stream ostringstream str2; // string stream ostringstream str3; // string stream ostringstream str4; // string stream ostringstream str5; // string stream // Absolute control flag str << "Absolute control : " << absoluteControl; putText(result, str.str(), Point(10, 90), CV_FONT_HERSHEY_PLAIN, 1.2, CV_RGB(0, 250, 0)); // Battery str2 << ardrone.getBatteryPercentage(); putText(result, str2.str(), Point(180, 33), CV_FONT_HERSHEY_PLAIN, 2, CV_RGB(0, 250, 0), 2); // Altitude str3 << ardrone.getAltitude(); putText(result, str3.str(), Point(440, 33), CV_FONT_HERSHEY_PLAIN, 2, CV_RGB(0, 250, 0), 2); // Show game info when game starts if (gameOn) { // Points str4 << points; putText(result, str4.str(), Point(WIDTH / 2.1, 45), CV_FONT_HERSHEY_PLAIN, 1, CV_RGB(0, 250, 0), 2); // Time int now = cvGetTickCount(); int passedSinceStart = ((now - gameTimeStart) / (cvGetTickFrequency() * 1000)) / 1000; gameTimeLeft = TIME_LIMIT - passedSinceStart; str5 << gameTimeLeft; if (isDroneConnected) putText(result, str5.str(), Point(WIDTH / 2.3, HEIGHT - 25), CV_FONT_HERSHEY_PLAIN, 2, CV_RGB(0, 250, 0), 2); else putText(result, str5.str(), Point(WIDTH / 2.2, WEBCAM_HEIGHT - 20), CV_FONT_HERSHEY_PLAIN, 2, CV_RGB(0, 250, 0), 2); } // Combine buffer with original image + opacity double opacity = 0.2; addWeighted(buffer, opacity, result, 1 - opacity, 0, result); return result; }