#include "testApp.h" string urlDecode(string &SRC) { string ret; char ch; int i, ii; for (i=0; i(ii); ret+=ch; i=i+2; } else { ret+=SRC[i]; } } return (ret); } //-------------------------------------------------------------- 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=vidGrabber.initGrabber(gw,gh); //base grab size learningRate = 0.001f; colorImg.allocate(gw,gh); grayImage.allocate(gw,gh); grayBg.allocate(gw,gh); grayDiff.allocate(gw,gh); mode=DISPLAY_FG; bLearnBakground = true; if (boundaries.size()==0) { boundaries.push_back(boundary()); } selectedBoundary=0; selectedPoint=-1; 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)); 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(); switch(method) { case METHOD_SIMPLE: if (bLearnBakground){ grayBg = grayImage; bLearnBakground = false; } break; case METHOD_ACCUM: cv::Mat img = grayImage.getCvImage(); //printf("img: %ix%i %i ch x %i bits\n",img.size().width,img.size().height,img.channels(),img.depth()); if (bLearnBakground) { img.convertTo(accumulator, CV_32FC1); startTime=ofGetElapsedTimef(); bLearnBakground=false; } cv::Mat im3; img.convertTo(im3, CV_32FC1); //printf("accumulator: %ix%i %i ch x %i bits\n",accumulator.size().width,accumulator.size().height,accumulator.channels(),accumulator.depth()); //printf("im3: %ix%i %i ch x %i bits\n",im3.size().width,im3.size().height,im3.channels(),im3.depth()); accumulateWeighted(im3, accumulator, max(1.0f/((ofGetElapsedTimef()-startTime)*30.0f),learningRate)); accumulator.convertTo(outmat,CV_8UC1); grayBg=new IplImage(outmat); } 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; resetBG(T); break; case 'f': bFlip=!bFlip; resetBG(T); 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; case '4': case '5': method=key-48; bLearnBakground=true; break; } } void testApp::resetBG(bool &chg){ bLearnBakground = true; } void testApp::volumeChanged(float &v){ for (int i=0;i-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: selectedPoint=boundaries[selectedBoundary].findPoint(p); if (selectedPoint<0) { boundaries[selectedBoundary].add(p); } else boundaries[selectedBoundary].points[selectedPoint]=p; break; case 1: for (int i=0;i