#include "testApp.h" //-------------------------------------------------------------- guiWindow::~guiWindow(){ cout << "gui window destroyed" << endl; } void guiWindow::setup(){} void guiWindow::setParent(testApp *p){ parent=p; } void guiWindow::draw(){ parent->gui.draw(); } //-------------------------------------------------------------- void testApp::setup(){ loadSettings("settings.xml"); gw=720; gh=576; vidGrabber.setVerbose(true); bGrab=false; //vidGrabber.initGrabber(gw,gh); //base grab size colorImg.allocate(gw,gh); grayImage.allocate(gw,gh); grayBg.allocate(gw,gh); grayDiff.allocate(gw,gh); mode=COLOUR; bLearnBakground = true; if (boundaries.size()==0) { boundaries.push_back(boundary()); } selectedBoundary=0; guiWin=new guiWindow(); ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0, 200, 200, OF_WINDOW); //ofAddListener(win2->events.windowResized, this, &testApp::windowEvent); //volume is set in loadSettings gui.setup("","panel.xml",0,0); gui.add(vol.setup("volume",volume,0,1.0,255)); vol.addListener(this,&testApp::volumeChanged); gui.add(bFlip.setup("flip grab", flip)); gui.add(bInvert.setup("invert grab", invert)); gui.add(thresh.setup("threshold",threshold,0,255,255)); win->setWindowTitle("config"); win->addListener(guiWin); guiWin->setup(); guiWin->setParent(this); } //-------------------------------------------------------------- void testApp::update(){ if (bGrab) { vidGrabber.grabFrame(); bool bNewFrame = vidGrabber.isFrameNew(); if (bNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels(), gw,gh); if (bFlip) colorImg.mirror(false,true); grayImage = colorImg; if (bInvert) grayImage.invert(); if (bLearnBakground == true){ grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading) bLearnBakground = false; } grayDiff.absDiff(grayBg, grayImage); grayDiff.threshold(threshold); contourFinder.findContours(grayDiff, 20, (gw*gh)/3, 10, true); // find holes } //generate events for (int i = 0; i < contourFinder.nBlobs; i++){ for (int j=0;j 255) threshold = 255; break; case '-': threshold --; if (threshold < 0) threshold = 0; break; case 'i': bInvert=!bInvert; break; case 'f': bFlip=!bFlip; break; case 's': saveSettings("settings.xml"); break; case 'a': boundaries.push_back(boundary()); selectedBoundary=boundaries.size()-1; break; case 'z': boundaries[selectedBoundary].undo(); break; case 'q': boundaries.erase(boundaries.begin()+selectedBoundary); if (selectedBoundary==boundaries.size()) selectedBoundary=0; break; case OF_KEY_PAGE_UP: selectedBoundary--; if (selectedBoundary<0) selectedBoundary=boundaries.size()-1; break; case OF_KEY_PAGE_DOWN: selectedBoundary=(selectedBoundary+1)%boundaries.size(); break; /* case OF_KEY_LEFT: boundaries[selectedBoundary].note--; break; case OF_KEY_RIGHT: boundaries[selectedBoundary].note++; break; */ case '1': case '2': case '3': mode=key-48; break; } } void testApp::volumeChanged(float &v){ for (int i=0;i