From 3411448d999ce36b5fcb14ca4829435308cbd70a Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 16 Apr 2012 18:35:55 +0100 Subject: player class --- gaunt01/src/testApp.cpp | 198 +++++++++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 88 deletions(-) (limited to 'gaunt01/src/testApp.cpp') diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 6660103..5f531a6 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -41,12 +41,18 @@ void testApp::setup(){ grayImage.allocate(640,480); grayBg.allocate(640,480); grayDiff.allocate(640,480); - */ + */ + + accumImg.allocate(640,480); + + bgImg.allocate(640,480); + bgImg.setUseTexture(true); + colorImg.allocate(640,480); colorImg.setUseTexture(true); - grayImage.allocate(ofGetWidth(),ofGetHeight()); - grayBg.allocate(ofGetWidth(),ofGetHeight()); + grayImage.allocate(640,480); + grayBg.allocate(640,480); grayDiff.allocate(ofGetWidth(),ofGetHeight()); @@ -82,6 +88,9 @@ void testApp::setup(){ mode=PLAY; drawStats=false; + + bgnum=1000; + firstframe=true; } @@ -185,23 +194,44 @@ void testApp::update(){ if (useCamera) { colorImg.setFromPixels(vidGrabber.getPixels(), 640,480); + //accumImg.setFromPixels(vidGrabber.getPixels(), 640,480); }else { colorImg.setFromPixels(vidPlayer.getPixels(), 640,480); + //accumImg.setFromPixels(vidPlayer.getPixels(), 640,480); } - - + + colorImg.updateTexture(); + grayImage = colorImg; + + if (firstframe) { + accumImg=grayImage; + firstframe=false; + } + else { + accumImg.addWeighted( grayImage, 1.0/bgnum ); + //accumImg/=(1.0+(0.25/bgnum)); + } + + bgImg=accumImg; + bgImg.updateTexture(); + + //test the scaling + + /* grayImage.resize(ofGetWidth(),ofGetHeight()); if (bLearnBakground == true){ grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading) bLearnBakground = false; } + */ // take the abs value of the difference between background and incoming and then threshold: - grayDiff.absDiff(grayBg, grayImage); + grayDiff.absDiff(bgImg, grayImage); grayDiff.threshold(threshold); //grayDiff.adaptiveThreshold( threshold); //int blockSize, int offset=0,bool invert=false, bool gauss=false); - grayDiff.erode_3x3(); + //grayDiff.erode_3x3(); + grayDiff.resize(ofGetWidth(),ofGetHeight()); // find contours which are between the size of 20 pixels and 1/3 the w*h pixels. // also, find holes is set to true so we will get interior contours as well.... @@ -210,41 +240,47 @@ void testApp::update(){ contourFinder.findContours(grayDiff, 200, (640*480)/3, 20, false); // don't find holes blobsManager.update(contourFinder.blobs); + //check players against blob ids - bland do ray casting, update players + //ids are always in order + //players can be a map vs ID + //check if a key exists in a map - map::count + //do we purge them or just stop drawing them? is it a problem inheriting tesselator re memory? + //if we keep them we can have a 'loserboard' + for(int i=0;i newPlayers; - float movethresh=10; for(int i=0;i