void* Run(cv::VideoCapture& capture) { int size = ivWidth*ivHeight; int count = 1; DebugInfo dbgInfo; cv::CascadeClassifier cascade; std::vector<cv::Rect> detectedFaces; std::vector<ObjectBox> trackBoxes; ObjectBox detectBox; // Initialize MultiObjectTLD #if LOADCLASSIFIERATSTART MultiObjectTLD p = MultiObjectTLD::loadClassifier((char*)CLASSIFIERFILENAME); #else MOTLDSettings settings(COLOR_MODE_RGB); settings.useColor = false; MultiObjectTLD p(ivWidth, ivHeight, settings); #endif if(cascadePath != "") cascade.load( cascadePath ); Matrix maRed; Matrix maGreen; Matrix maBlue; unsigned char img[size*3]; while(!ivQuit) { /* if(reset){ p = *(new MultiObjectTLD(ivWidth, ivHeight, COLOR_MODE_RGB)); reset = false; } if(load){ p = MultiObjectTLD::loadClassifier(CLASSIFIERFILENAME); load = false; } */ #if TIMING c_end = std::clock(); std::cout << "Total: " << (c_end-c_start) << std::endl; c_start = std::clock(); #endif // Grab an image if(!capture.grab()){ std::cout << "error grabbing frame" << std::endl; break; } cv::Mat frame; capture.retrieve(frame); frame.copyTo(curImage); //BGR to RGB // for(int j = 0; j<size; j++){ // img[j] = frame.at<cv::Vec3b>(j).val[2]; // img[j+size] = frame.at<cv::Vec3b>(j).val[1]; // img[j+2*size] = frame.at<cv::Vec3b>(j).val[0]; // } #if TIMING c_start1 = std::clock(); #endif for(int i = 0; i < ivHeight; ++i){ for(int j = 0; j < ivWidth; ++j){ img[i*ivWidth+j] = curImage.at<cv::Vec3b>(i,j).val[2]; img[i*ivWidth+j+size] = curImage.at<cv::Vec3b>(i,j).val[1]; img[i*ivWidth+j+2*size] = curImage.at<cv::Vec3b>(i,j).val[0]; } } #if TIMING c_end1 = std::clock(); std::cout << "time1: " << (c_end1-c_start1) << std::endl; #endif // for(int i = 0; i < ivHeight; ++i){ // for(int j = 0; j < ivWidth; ++j){ // curImage.at<cv::Vec3b>(i,j).val[2] = 0; // curImage.at<cv::Vec3b>(i,j).val[1] = 0; // curImage.at<cv::Vec3b>(i,j).val[0] = 0; // } // } // cv::imshow("MOCTLD", curImage); #if TIMING c_start2 = std::clock(); #endif // Process it with motld p.processFrame(img); #if TIMING c_end2 = std::clock(); std::cout << "time2: " << (c_end2-c_start2) << std::endl; #endif // Add new box if(mouseMode == MOUSE_MODE_ADD_BOX){ p.addObject(mouseBox); mouseMode = MOUSE_MODE_IDLE; } if(mouseMode == MOUSE_MODE_ADD_GATE){ p.addGate(gate); mouseMode = MOUSE_MODE_IDLE; } if(((count%20)==0) && cascadeDetect) { cascade.detectMultiScale( frame, detectedFaces, 1.1, 2, 0 //|CASCADE_FIND_BIGGEST_OBJECT //|CASCADE_DO_ROUGH_SEARCH |cv::CASCADE_SCALE_IMAGE, cv::Size(30, 30) ); Ndetections = detectedFaces.size(); for( std::vector<cv::Rect>::const_iterator r = detectedFaces.begin(); r != detectedFaces.end(); r++ ) { detectBox.x = r->x; detectBox.y = r->y; detectBox.width = r->width; detectBox.height = r->height; if(p.isNewObject(detectBox)) p.addObject(detectBox); } //printf("size detectedFaces: %i\n", detectedFaces.size()); } count++; // Display result HandleInput(); p.getDebugImage(img, maRed, maGreen, maBlue, drawMode); #if TIMING c_start3 = std::clock(); #endif BGR2RGB(maRed, maGreen, maBlue); #if TIMING c_end3 = std::clock(); std::cout << "time3: " << (c_end3-c_start3) << std::endl; #endif drawGate(); drawMouseBox(); dbgInfo.NObjects = p.getObjectTotal(); dbgInfo.side0Cnt = p.getSide0Cnt(); dbgInfo.side1Cnt = p.getSide1Cnt(); writeDebug(dbgInfo); cv::imshow("MOCTLD", curImage); p.enableLearning(learningEnabled); if(save){ p.saveClassifier((char*)CLASSIFIERFILENAME); save = false; } } //delete[] img; capture.release(); return 0; }
void display(){ if(exitting) { exit(0); return; } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0.0f,0.0f,0.0f,0.0f); // Black Background glPushMatrix(); gluLookAt(cam.getCamX(), cam.getCamY(), cam.getCamZ(), cam.getLookAtX(), cam.getLookAtY(), cam.getLookAtZ(), 0.0, 1.0, 0.0); place_lights(); if(!gameOver) { if(starting) { glPushMatrix(); //glTranslatef(.5,.5,.5); drawIntroScreen(); glPopMatrix(); } glPushMatrix(); scene.draw(); glPopMatrix(); glPushMatrix(); if(placingTower){ setMaterial(Exp); glNormal3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON);{ glVertex3f(worldX - GRID_SIZE*2.0, 0.001, worldZ - GRID_SIZE*2.0); glVertex3f(worldX - GRID_SIZE*2.0, 0.001, worldZ + GRID_SIZE*2.0); glVertex3f(worldX + GRID_SIZE*2.0, 0.001, worldZ + GRID_SIZE*2.0); glVertex3f(worldX + GRID_SIZE*2.0, 0.001, worldZ - GRID_SIZE*2.0); }glEnd(); } if(towerSelected){ setMaterial(Exp); glNormal3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON);{ glVertex3f(towerSelect->getX() - GRID_SIZE*2.0 + P1_POSX, 0.001, towerSelect->getZ() - GRID_SIZE*2.0 + P1_POSZ); glVertex3f(towerSelect->getX() - GRID_SIZE*2.0 + P1_POSX, 0.001, towerSelect->getZ() + GRID_SIZE*2.0 + P1_POSZ); glVertex3f(towerSelect->getX() + GRID_SIZE*2.0 + P1_POSX, 0.001, towerSelect->getZ() + GRID_SIZE*2.0 + P1_POSZ); glVertex3f(towerSelect->getX() + GRID_SIZE*2.0 + P1_POSX, 0.001, towerSelect->getZ() - GRID_SIZE*2.0 + P1_POSZ); }glEnd(); } p1.draw(placingTower); // GL_RENDER for normal, GL_SELECT for picking. opponent.player.draw(false); //drawProjectiles(); glPopMatrix(); vfc::extractPlanes(); glColor3f(0.8, 0.5, 0.3); float lx = tlx*2.0*GRID_SIZE - GRID_SIZE*float(GRID_WIDTH) + GRID_SIZE + (GRID_SIZE * 2); float lz = tly*2.0*GRID_SIZE - GRID_SIZE*float(GRID_HEIGHT) + GRID_SIZE + (GRID_SIZE * 2); // draw root directories glPushMatrix(); glTranslatef(0.0, 2 * GRID_SIZE, 1.0 * GRID_HEIGHT * GRID_SIZE + (GRID_SIZE * 8)); glPushMatrix(); glScalef(0.25, 0.25, 0.25); glCallList(vtd_dl::rootDL); glPopMatrix(); glTranslatef(GRID_WIDTH * GRID_SIZE * 3, 0.0, 0.0); glPushMatrix(); glScalef(0.25, 0.25, 0.25); glCallList(vtd_dl::rootDL); glPopMatrix(); glPopMatrix(); if(!starting){ glPushMatrix(); renderUI(GW, GH,&p1,&opponent.player,((CYCLE_TIME-last_cycle)/1000.0), GL_RENDER); glPopMatrix(); } drawMouseBox(clicked); } else { if(winner == COMPUTER_WIN) drawBlueScreen(); else drawWinScreen(); } glPopMatrix(); glutSwapBuffers(); }
// doDraw //--------------------------------------------------------------------------- void MiniMapView::doDraw(const Surface &viewArea, const Surface &clientArea) { assert(this != 0); assert(viewArea.getDoesExist()); assert(clientArea.getDoesExist()); if (decreaseSize != 0) { doDecreaseSize(decreaseSize); decreaseSize = 0; } if (increaseSize != 0) { doIncreaseSize(increaseSize); increaseSize = 0; } float dt = TimerInterface::getTimeSlice(); Surface *miniMap; miniMap = MiniMapInterface::getMiniMap(); if (needScale) { scaleGroupWait += dt; if (scaleGroupWait > 1.0f) { miniMapSurface.create(getViewRect().getSize(), getViewRect().getSize().x , 1); //miniMapSurface.scale(getViewRect().getSize()); iRect r(iXY(0, 0), getViewRect().getSize()); miniMapSurface.bltScale(*miniMap, r); needScale = false; scaleGroupWait = 0.0f; } } iRect r(getViewRect().min, getViewRect().max); if (needScale) { // Draw the slow on the fly scaled map. if (mapDrawType == MAP_SOLID) { clientArea.bltScale(*miniMap, r); } else if (mapDrawType == MAP_2080) { clientArea.bltBlendScale(*miniMap, r, Palette::colorTable2080); } else if (mapDrawType == MAP_4060) { clientArea.bltBlendScale(*miniMap, r, Palette::colorTable4060); } //else if (mapDrawType == MAP_BLEND_GREEN) //{ //clientArea.bltLookup(iRect(iXY(0, 0), getSize()), Palette::green256.getColorArray()); //} else if (mapDrawType == MAP_BLEND_GRAY) { clientArea.bltLookup(iRect(iXY(0, 0), getSize()), Palette::gray256.getColorArray()); } else if (mapDrawType == MAP_BLEND_DARK_GRAY) { clientArea.bltLookup(iRect(iXY(0, 0), getSize()), Palette::darkGray256.getColorArray()); } else if (mapDrawType == MAP_BLACK) { clientArea.fill(Color::black); } else if (mapDrawType == MAP_TRANSPARENT) {} } else { // Draw the fast not on the fly scaled map. if (mapDrawType == MAP_SOLID) { miniMapSurface.blt(clientArea, 0, 0); } else if (mapDrawType == MAP_2080) { clientArea.blendIn(miniMapSurface, iXY(0, 0), Palette::colorTable2080); } else if (mapDrawType == MAP_4060) { clientArea.blendIn(miniMapSurface, iXY(0, 0), Palette::colorTable4060); } //else if (mapDrawType == MAP_BLEND_GREEN) //{ //clientArea.bltLookup(iRect(iXY(0, 0), getSize()), Palette::green256.getColorArray()); //} else if (mapDrawType == MAP_BLEND_GRAY) { clientArea.bltLookup(iRect(iXY(0, 0), getSize()), Palette::gray256.getColorArray()); } else if (mapDrawType == MAP_BLEND_DARK_GRAY) { clientArea.bltLookup(iRect(iXY(0, 0), getSize()), Palette::darkGray256.getColorArray()); } else if (mapDrawType == MAP_BLACK) { clientArea.fill(Color::black); } else if (mapDrawType == MAP_TRANSPARENT) {} } // Draw a hairline border. //viewArea.drawRect(Color::white); viewArea.drawLookupBorder(Palette::darkGray256.getColorArray()); // Draw the world view box. clientArea.bltLookup(MiniMapInterface::getWorldWindow(), Palette::darkGray256.getColorArray()); // Draw the units and such on the minimap. MiniMapInterface::annotateMiniMap((Surface &) clientArea); // Draw the world view box corners. clientArea.drawBoxCorners(MiniMapInterface::getWorldWindow(), 5, Color::white); // Draw an inner black rect inside the outer white rect, for visibility reasons. //iRect innerRect(MiniMapInterface::getWorldWindow()); // //innerRect.min += 1; //innerRect.max -= 1; // //clientArea.drawBoxCorners(innerRect, 4, Color::black); // If the mouse is over the client area, then change the cursor. if (getClientRect().contains(getScreenToClientPos(mouse.getScreenPos()))) { if (selectionAnchor) { // Since we are selecting units, draw the selection box. clientArea.drawRect(selectionAnchorDownPos, selectionAnchorCurPos, Color::white); } else { // Draw a box which show where the area which you click will be located. drawMouseBox(clientArea); } } GameTemplateView::doDraw(viewArea, clientArea); } // end doDraw