From 0e8f0361c1068eb4c2f634dfcf4e1762d87f40d2 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sat, 31 Mar 2012 16:44:02 +0100 Subject: implementing trap door --- gaunt01/src/testApp.cpp | 150 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 107 insertions(+), 43 deletions(-) (limited to 'gaunt01/src/testApp.cpp') diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 00658b4..1ab413b 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -1,23 +1,28 @@ #include "testApp.h" //-------------------------------------------------------------- +//units ~ 10cm +// void testApp::setup(){ + + bLearnBakground = true; + cam_angle=0; + threshold = 80; + + loadSettings("settings.xml"); #ifdef _USE_LIVE_VIDEO vidGrabber.setVerbose(true); vidGrabber.initGrabber(320,240); #else - vidPlayer.loadMovie("camoutput.mov"); + vidPlayer.loadMovie("camoutput.wmv"); //footage/ camera needs to be the same res as opencv planes and output vidPlayer.play(); #endif - colorImg.allocate(320,240); - grayImage.allocate(320,240); - grayBg.allocate(320,240); - grayDiff.allocate(320,240); - - bLearnBakground = true; - threshold = 80; + colorImg.allocate(640,480); + grayImage.allocate(640,480); + grayBg.allocate(640,480); + grayDiff.allocate(640,480); ofVec3f centre=ofVec3f(ofGetWidth()/2,0,0); ofVec3f normal=ofVec3f(0,0,-1); @@ -25,16 +30,17 @@ void testApp::setup(){ plane=ofPlane(centre,normal); plane.color=ofColor(255,255,255); - projector=ofProjector(1.535f, ofVec2f(0.0f, 0.5f),ofGetWidth(),ofGetHeight()); - projector.setPosition(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight()); + projector=ofProjector(2.0f, ofVec2f(0.0f, 0.0f),ofGetWidth(),ofGetHeight()); //1.535f + projector.setPosition(ofGetWidth()/2,ofGetHeight()/2,-ofGetWidth()); + projector.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0)); cam=ofCamera(); - cam.setPosition(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight()); - cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0)); - cam.setFov(54.13); - - cam_angle=0; - + cam.setPosition(ofGetWidth()/2,ofGetHeight()/2,-ofGetWidth()); + cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0)); + cam.setFov(42.0); //39.85); //53.13); + + trapDoor=trapdoor(ofRectangle(0,0,ofGetWidth(),ofGetHeight()),ofVec2f(20,20)); + } //-------------------------------------------------------------- @@ -56,7 +62,7 @@ void testApp::update(){ #ifdef _USE_LIVE_VIDEO colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); #else - colorImg.setFromPixels(vidPlayer.getPixels(), 320,240); + colorImg.setFromPixels(vidPlayer.getPixels(), 640,480); #endif grayImage = colorImg; @@ -71,7 +77,9 @@ void testApp::update(){ // 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.... - contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, false); // don't find holes + + //hard coded size threshold of 100 pix + contourFinder.findContours(grayDiff, 200, (640*480)/3, 20, false); // don't find holes } } @@ -96,6 +104,8 @@ void testApp::draw(){ // we could draw the whole contour finder //contourFinder.draw(360,540); + + //keep running background average- how do you use a custom background colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); @@ -117,27 +127,65 @@ void testApp::draw(){ } ofPopMatrix(); - cam.end(); - - ofSphere(pos.x,pos.y,pos.z,5); - - for (int i = 0; i < contourFinder.nBlobs; i++){ + + + //ofSphere(pos.x,pos.y,pos.z,5); + + vector newPlayers; + float movethresh=10; + + for (int i = 0; i < contourFinder.nBlobs; i++){ + //do some bounds checking, size threshold and overlap removal + //in order to translate blobs into players + //attempt to track players - maintain ID no + //attempt to base blobs + //TODO attempt to estimate bounds shape + //project all of this into the 3D space + ofRectangle r=contourFinder.blobs[i].boundingRect; + + ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2)); + contourFinder.blobs[i].draw(0,0); - ofPoint p=contourFinder.blobs[i].centroid; - ofVec3f pp; - cam.begin(); - ofPushMatrix(); - - ofRotate(cam_angle,1,0,0); - ray=projector.castPixel(p.x,(ofGetHeight()/2)-p.y); //(ofGetHeight()-y)); - bool hit = plane.intersect(ray,pp); - ofBox(pp,50); - ofPopMatrix(); - cam.end(); + ofSetHexColor(0xffff00); + + char numStr[16]; + sprintf(numStr, "%i", i); + ofDrawBitmapString(numStr, r.x, r.y); + + ofVec3f pp; + ray=projector.castPixel(blobBase.x,blobBase.y); //(ofGetHeight()-y)); + bool hit = plane.intersect(ray,pp); + + + for (int i=0;i