#include "testApp.h" //-------------------------------------------------------------- //units ~ 10cm // void testApp::setup(){ bLearnBakground = true; cam_angle=0; threshold = 80; loadSettings("settings.xml"); vidPlayer.loadMovie("camoutput.mov"); //footage/ camera needs to be the same res as opencv planes and output vidPlayer.setLoopState(OF_LOOP_NORMAL); vidGrabber.setVerbose(true); if (vidGrabber.initGrabber(640,480)) { hasCamera=true; useCamera=true; } else { hasCamera=false; useCamera=false; vidPlayer.play(); } colorImg.allocate(640,480); colorImg.setUseTexture(true); grayImage.allocate(640,480); grayBg.allocate(640,480); grayDiff.allocate(640,480); blobsManager.normalizePercentage = 0.7; blobsManager.giveLowestPossibleIDs = false; blobsManager.maxUndetectedTime = 500; blobsManager.minDetectedTime = 500; blobsManager.debugDrawCandidates = true; ofVec3f centre=ofVec3f(ofGetWidth()/2,0,0); ofVec3f normal=ofVec3f(0,0,-1); ray=ofRay(); plane=ofPlane(centre,normal); plane.color=ofColor(255,255,255); 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,-ofGetWidth()); cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0)); cam.setFov(41.1); //39.85); //53.13); cam.cacheMatrices(); //stop error messages testpts=new ofVec3f[4]; trapDoor=trapdoor(screen2plane(ofVec2f(ofGetWidth(),0)),screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())),ofVec2f(30,30)); updatePlane(); mode=PLAY; } ofVec2f testApp::screen2plane(ofVec2f screenpos){ ofVec3f p; ray=projector.castPixel(screenpos.x,screenpos.y); bool hit = plane.intersect(ray,p); return ofVec2f(p.x,pow(pow(p.y,2)+pow(p.z,2),0.5f)); } ofVec3f testApp::plane2world(ofVec2f planepos){ return ofVec3f(planepos.x,planepos.y,0); } bool testApp::rectsCross(ofRectangle rect1,ofRectangle rect2) { bool overlap=true; //must overlap in x and y if (rect1.x corners=trapDoor.getCorners(); ofVec2f screenCorners[4]; for (int i=0;i newPlayers; float movethresh=10; for(int i=0;i 255) threshold = 255; break; case '-': threshold --; if (threshold < 0) threshold = 0; break; case 'a': cam_angle+=1; updatePlane(); break; case 'z': cam_angle-=1; updatePlane(); break; case 's': saveSettings("settings.xml"); break; case '1': mode=PLAY; break; case '2': mode=CALIBRATE; break; } } //-------------------------------------------------------------- void testApp::keyReleased(int key){ } //-------------------------------------------------------------- void testApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void testApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ pos=ofVec2f(x,y); //if (hit) printf("ray:%i,%i hit plane:%f,%f,%f\n",x,y,pos.x,pos.y,pos.z); //else printf("ray:%i,%i missed plane\n",x,y); trapDoor.startPos(screen2plane(pos)); updatePlane(); } //-------------------------------------------------------------- void testApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void testApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo){ } void testApp::loadSettings(string filename){ if( !XML.loadFile(filename) ){ printf("unable to load %s check data/ folder\n",filename.c_str()); }else{ cam_angle=ofToInt(XML.getAttribute("gauntlet","cam_angle","none",0)); threshold=ofToInt(XML.getAttribute("gauntlet","threshold","none",0)); printf("loaded %s\n",filename.c_str()); } } //-------------------------------------------------------------- void testApp::saveSettings(string filename){ XML.setAttribute("gauntlet","cam_angle",ofToString(cam_angle),0); XML.setAttribute("gauntlet","threshold",ofToString(threshold),0); XML.saveFile(filename); printf("saved %s\n",filename.c_str()); }