From ed539c88af8e18ae3b505e324319b956944e0d91 Mon Sep 17 00:00:00 2001 From: Comment Date: Tue, 29 Jan 2013 17:23:14 +0000 Subject: working with accumulation --- src/testApp.cpp | 137 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 86 insertions(+), 51 deletions(-) (limited to 'src/testApp.cpp') diff --git a/src/testApp.cpp b/src/testApp.cpp index 0392c92..5928ee5 100755 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -18,15 +18,17 @@ void testApp::setup(){ gh=576; vidGrabber.setVerbose(true); - bGrab=false; - //vidGrabber.initGrabber(gw,gh); //base grab size + bGrab=vidGrabber.initGrabber(gw,gh); //base grab size + + learningRate = 0.01f; colorImg.allocate(gw,gh); grayImage.allocate(gw,gh); grayBg.allocate(gw,gh); grayDiff.allocate(gw,gh); - mode=COLOUR; + mode=DISPLAY_FG; + method=METHOD_SIMPLE; bLearnBakground = true; @@ -34,6 +36,7 @@ void testApp::setup(){ boundaries.push_back(boundary()); } selectedBoundary=0; + selectedPoint=-1; guiWin=new guiWindow(); ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0, 200, 200, OF_WINDOW); @@ -45,44 +48,61 @@ void testApp::setup(){ gui.add(vol.setup("volume",volume,0,1.0,255)); vol.addListener(this,&testApp::volumeChanged); gui.add(bFlip.setup("flip grab", flip)); + bFlip.addListener(this,&testApp::resetBG); gui.add(bInvert.setup("invert grab", invert)); + bInvert.addListener(this,&testApp::resetBG); 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-1) boundaries[selectedBoundary].points[selectedPoint]=ofPoint(x,y,0); } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ + ofPoint p=ofPoint(x,y,0); switch (button) { case 0: - boundaries[selectedBoundary].add(ofPoint(x,y,0)); + selectedPoint=boundaries[selectedBoundary].findPoint(p); + if (selectedPoint<0) { + selectedPoint=boundaries[selectedBoundary].points.size(); + boundaries[selectedBoundary].add(p); + } + else boundaries[selectedBoundary].points[selectedPoint]=p; break; case 1: for (int i=0;i