summaryrefslogtreecommitdiff
path: root/gaunt01/src/testApp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gaunt01/src/testApp.cpp')
-rw-r--r--gaunt01/src/testApp.cpp198
1 files changed, 110 insertions, 88 deletions
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<blobsManager.blobs.size();i++){
+ ofxCvBlob blob = blobsManager.blobs.at(i);
+ ofRectangle r=blob.boundingRect;
+ ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2));
+ ofVec3f pp,rp;
+ ray=projector.castPixel(blobBase.x,blobBase.y);
+ bool hit = plane.intersect(ray,pp);
+ rp=pp.getRotated(cam_angle,ofVec3f(-1,0,0));
+ players[blobsManager.blobs.at(i).id].setPosition(rp);
+ players[blobsManager.blobs.at(i).id].update(blob); //create model
+ }
}
-
+ if (trapDoor.checkUpdate(players)) updatePlane();
}
//--------------------------------------------------------------
void testApp::draw(){
ofBackground(0,0,0);
- cam.begin();
-
- if (trapDoor.checkUpdate(players)) updatePlane();
+ cam.begin();
switch(mode) {
case PLAY:
glDisable(GL_DEPTH_TEST);
- colorImg.draw(0,0,ofGetWidth(),ofGetHeight());
- ofSetHexColor(0x000000);
- ofRect(0,0,ofGetWidth(),ofGetHeight());
- //PITA
+
ofSetHexColor(0xffffff);
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
trapDoor.draw();
ofPopMatrix();
+
ofSetHexColor(0xffffff);
- /*
- glEnable(GL_BLEND);
- glBlendFunc(GL_CONSTANT_ALPHA,GL_ONE);
- glBlendColor(1.0f,1.0f,1.0f, 0.5f);
- glDisable(GL_BLEND);
- */
-
- bindTexture(colorImg);
- ground.draw();
- unbindTexture(colorImg);
-
+ bindTexture(bgImg);
+ ground.draw();
+ unbindTexture(bgImg);
+
Bird.update(players);
ofPushMatrix();
@@ -252,40 +288,41 @@ void testApp::draw(){
Bird.drawShadow();
ofPopMatrix();
+ glDisable(GL_DEPTH_TEST);
+ ofSetHexColor(0xffffff);
+ colorImg.getTextureReference().bind();
+ for(int i=0;i<blobsManager.blobs.size();i++){
+ players[blobsManager.blobs.at(i).id].draw();
+ }
+ colorImg.getTextureReference().unbind();
+ //ofxCvBlob blob=contourFinder.blobs[i];
+ //if (rectsCross(blob.boundingRect,trapDoor.getBoundingRect())){ //ALWAYS draw players?
+ //create outline mesh
/*
- glEnable(GL_BLEND);
- glBlendFunc(GL_CONSTANT_ALPHA,GL_ONE);
- glBlendColor(1.0f,0.5f,0.1f, 0.5f);
- ofRect(trapDoor.getBoundingRect());
- glDisable(GL_BLEND);
+ playeroutline=ofPolyline(blob.pts);
+ tesselator.tessellateToMesh(playeroutline,OF_POLY_WINDING_NONZERO,player,true);
+ for (int i=0;i<player.getNumVertices();i++) {
+ ofVec3f v=player.getVertex(i);
+ player.addTexCoord(ofVec2f(v.x,v.y));
+ }
+
+
+ //figure out if player has stood on trap door
+ //get screen basepoint
+ ofRectangle r=blob.boundingRect;
+ ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2));
+ if (trapDoor.getInnerRect().inside(blobBase.x,blobBase.y)) {
+ trapDoor.trigger();
+
+ }
+ else {
*/
- for (int i = 0; i < contourFinder.nBlobs; i++){
- ofxCvBlob blob=contourFinder.blobs[i];
- //if (rectsCross(blob.boundingRect,trapDoor.getBoundingRect())){ //ALWAYS draw players?
- //create outline mesh
- playeroutline=ofPolyline(blob.pts);
- tesselator.tessellateToMesh(playeroutline,OF_POLY_WINDING_NONZERO,player,true);
- for (int i=0;i<player.getNumVertices();i++) {
- ofVec3f v=player.getVertex(i);
- player.addTexCoord(ofVec2f(v.x,v.y));
- }
-
- //figure out if player has stood on trap door
- //get screen basepoint
- ofRectangle r=blob.boundingRect;
- ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2));
- if (trapDoor.getInnerRect().inside(blobBase.x,blobBase.y)) {
- trapDoor.trigger();
-
- ofPushMatrix();
- ofTranslate(0,0,trapDoor.getFalldist()*ofGetScreenHeight());
- colorImg.getTextureReference().bind();
- player.draw(); //trapdoor.getoffset());
- colorImg.getTextureReference().unbind();
- ofPopMatrix();
- }
- }
- //}
+
+ //draw players is in front of trap door or shadow
+
+
+
+
@@ -304,7 +341,8 @@ void testApp::draw(){
//contourFinder.draw(360,540);
//keep running background average- how do you use a custom background
ofSetHexColor(0xffffff);
- colorImg.draw(0,0,ofGetWidth(),ofGetHeight());
+ //colorImg.draw(0,0,ofGetWidth(),ofGetHeight());
+ bgImg.draw(0,0,ofGetWidth(),ofGetHeight());
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
@@ -329,39 +367,18 @@ void testApp::draw(){
ofPopMatrix();
- vector<ofVec3f> newPlayers;
- float movethresh=10;
for(int i=0;i<blobsManager.blobs.size();i++){
+
ofxCvBlob blob = blobsManager.blobs.at(i);
- ofRectangle r=blob.boundingRect;
- ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2));
blob.draw(0,0);
ofPoint p=blob.centroid;
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<players.size();i++) {
- if (abs(players[i].x-pp.x)<10&&abs(players[i].z-pp.z)) {
- //identified a player
- //this is flawed: tracking boxes in a skewed axis
- //how to get UV coords on the plane
- //maybe rotate the camera instead of the plane
-
- //for the bird interaction, need to get player coords in the ground axis.
- //for the door interaction, need to build player outline in the screen axis
-
- //for the door, first determine if the boundings cross - create overlay
- //if the base centre is in the hole- trigger falling behaviour
-
- }
- }
+ sprintf(numStr, "%i", blobsManager.blobs[i].id);
+ ofDrawBitmapString(numStr, blob.boundingRect.x, blob.boundingRect.y);
ofPushMatrix();
- ofTranslate(pp);
ofRotate(cam_angle,1,0,0);
+ ofTranslate(players[blobsManager.blobs.at(i).id].getPosition());
ofBox(0,-10,0,20);
//TODO get this into plane axis
ofPopMatrix();
@@ -375,10 +392,15 @@ void testApp::draw(){
break;
}
if (drawStats||mode==CALIBRATE) {
- ofSetHexColor(0xffffff);
- char reportStr[1024];
- sprintf(reportStr, "threshold %i\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate());
- ofDrawBitmapString(reportStr, 10, ofGetHeight()-40);
+ ofSetHexColor(0xffffff);
+ char reportStr[1024];
+ sprintf(reportStr, "threshold %i\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate());
+ ofDrawBitmapString(reportStr, 10, ofGetHeight()-40);
+ char numStr[16];
+ for(int i=0;i<blobsManager.blobs.size();i++){
+ sprintf(numStr, "%i", blobsManager.blobs[i].id);
+ ofDrawBitmapString(numStr, 10+(i*30), ofGetHeight()-55);
+ }
}
cam.end();
}