diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-03-28 00:42:08 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-03-28 00:42:08 +0100 |
| commit | a47b39541a7f60dfdda921c9598abe947e1e6ad9 (patch) | |
| tree | 34f85aa65d56793d2c42a83df5b025be7a142669 /gaunt01 | |
| parent | 3badbcdf8d8a0005543521849694fa481dfce628 (diff) | |
rayhit still iffy. starting morpher
Diffstat (limited to 'gaunt01')
| -rw-r--r-- | gaunt01/addons.make | 1 | ||||
| -rw-r--r-- | gaunt01/config.make | 2 | ||||
| -rw-r--r-- | gaunt01/gaunt01.cbp | 6 | ||||
| -rw-r--r-- | gaunt01/gaunt01.layout | 9 | ||||
| -rw-r--r-- | gaunt01/src/main.cpp | 2 | ||||
| -rw-r--r-- | gaunt01/src/testApp.cpp | 94 | ||||
| -rw-r--r-- | gaunt01/src/testApp.h | 8 |
7 files changed, 94 insertions, 28 deletions
diff --git a/gaunt01/addons.make b/gaunt01/addons.make index 886857d..9e525f4 100644 --- a/gaunt01/addons.make +++ b/gaunt01/addons.make @@ -1 +1,2 @@ ofxOpenCv +ofxRay diff --git a/gaunt01/config.make b/gaunt01/config.make index 702abf0..9ce3e2f 100644 --- a/gaunt01/config.make +++ b/gaunt01/config.make @@ -3,7 +3,7 @@ # OF_ROOT allows to move projects outside apps/* just set this variable to the # absoulte path to the OF root folder -OF_ROOT = ../../of_preRelease_v007_linux +OF_ROOT = ../../openFrameworks-020912 # USER_CFLAGS allows to pass custom flags to the compiler diff --git a/gaunt01/gaunt01.cbp b/gaunt01/gaunt01.cbp index a53c7b0..1ad4c32 100644 --- a/gaunt01/gaunt01.cbp +++ b/gaunt01/gaunt01.cbp @@ -81,6 +81,12 @@ <Unit filename="../../../addons/ofxOpenCv/src/ofxOpenCv.h"> <Option virtualFolder="addons/ofxOpenCv/src" /> </Unit> + <Unit filename="Makefile"> + <Option virtualFolder="build config/" /> + </Unit> + <Unit filename="addons.make"> + <Option virtualFolder="build config/" /> + </Unit> <Unit filename="config.make"> <Option virtualFolder="build config" /> </Unit> diff --git a/gaunt01/gaunt01.layout b/gaunt01/gaunt01.layout index 04e7795..e5fb8e8 100644 --- a/gaunt01/gaunt01.layout +++ b/gaunt01/gaunt01.layout @@ -1,13 +1,16 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_layout_file> <ActiveTarget name="Debug" /> + <File name="addons.make" open="0" top="0" tabpos="0"> + <Cursor position="16" topLine="0" /> + </File> <File name="config.make" open="1" top="0" tabpos="3"> - <Cursor position="171" topLine="0" /> + <Cursor position="192" topLine="0" /> </File> <File name="src/testApp.cpp" open="1" top="1" tabpos="1"> - <Cursor position="389" topLine="6" /> + <Cursor position="1491" topLine="16" /> </File> <File name="src/testApp.h" open="1" top="0" tabpos="2"> - <Cursor position="14" topLine="0" /> + <Cursor position="58" topLine="0" /> </File> </CodeBlocks_layout_file> diff --git a/gaunt01/src/main.cpp b/gaunt01/src/main.cpp index 6a32c6a..e502a4d 100644 --- a/gaunt01/src/main.cpp +++ b/gaunt01/src/main.cpp @@ -6,7 +6,7 @@ int main( ){ ofAppGlutWindow window; - ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context + ofSetupOpenGL(&window, 640,480, OF_WINDOW); // <-------- setup the GL context // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index fdff756..00658b4 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -18,6 +18,23 @@ void testApp::setup(){ bLearnBakground = true; threshold = 80; + + 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(1.535f, ofVec2f(0.0f, 0.5f),ofGetWidth(),ofGetHeight()); + projector.setPosition(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight()); + + cam=ofCamera(); + cam.setPosition(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight()); + cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0)); + cam.setFov(54.13); + + cam_angle=0; + } //-------------------------------------------------------------- @@ -54,7 +71,7 @@ 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, true); // find holes + contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, false); // don't find holes } } @@ -62,6 +79,7 @@ void testApp::update(){ //-------------------------------------------------------------- void testApp::draw(){ + /* // draw the incoming, the grayscale, the bg and the thresholded difference ofSetHexColor(0xffffff); colorImg.draw(20,20); @@ -70,45 +88,68 @@ void testApp::draw(){ grayDiff.draw(360,280); // then draw the contours: - + */ ofFill(); ofSetHexColor(0x333333); - ofRect(360,540,320,240); - ofSetHexColor(0xffffff); + //ofRect(360,540,320,240); + ofSetHexColor(0xa0a0a0); // we could draw the whole contour finder //contourFinder.draw(360,540); - // or, instead we can draw each blob individually, - // this is how to get access to them: - for (int i = 0; i < contourFinder.nBlobs; i++){ - contourFinder.blobs[i].draw(360,540); - } - // finally, a report: - - ofSetHexColor(0xffffff); - char reportStr[1024]; - sprintf(reportStr, "bg subtraction and blob detection\npress ' ' to capture bg\nthreshold %i (press: +/-)\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate()); - ofDrawBitmapString(reportStr, 20, 600); + colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); - float gap=ofGetHeight()-ofGetWidth(); + cam.begin(); + ofPushMatrix(); - ofTranslate(0,ofGetHeight(),0); ofRotate(cam_angle,1,0,0); - ofTranslate(0,-ofGetHeight(),0); - for (float i=0;i<ofGetWidth();i+=ofGetWidth()/10) { + for (float i=0;i<=ofGetWidth();i+=ofGetWidth()/10) { glBegin(GL_LINES); - glVertex3f(i,gap,0); - glVertex3f(i,ofGetHeight(),0); + glVertex3f(i,0,0); + glVertex3f(i,ofGetWidth(),0); glEnd(); glBegin(GL_LINES); - glVertex3f(0,i+gap,0); - glVertex3f(ofGetWidth(),i+gap,0); + glVertex3f(0,i,0); + glVertex3f(ofGetWidth(),i,0); glEnd(); } + ofPopMatrix(); + cam.end(); + + ofSphere(pos.x,pos.y,pos.z,5); + + for (int i = 0; i < contourFinder.nBlobs; i++){ + 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(); + + } + + + + // finally, a report: + + ofSetHexColor(0xffffff); + char reportStr[1024]; + sprintf(reportStr, "threshold %i\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate()); + ofDrawBitmapString(reportStr, 10, 215); + + + } //-------------------------------------------------------------- @@ -133,6 +174,7 @@ void testApp::keyPressed(int key){ cam_angle-=1; break; } + plane.setNormal(ofVec3f(0,sin(cam_angle*0.01745329),-cos(cam_angle*0.01745329))); } //-------------------------------------------------------------- @@ -157,6 +199,12 @@ void testApp::mousePressed(int x, int y, int button){ //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ + ray=projector.castPixel(x,((3*(ofGetHeight()/2))-y)); //(ofGetHeight()-y)); + bool hit = plane.intersect(ray,pos); + //pos=ofVec3f(pos.x*2,pos.y*2,pos.z*2); + 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); + } diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h index eafbf00..de13eae 100644 --- a/gaunt01/src/testApp.h +++ b/gaunt01/src/testApp.h @@ -3,6 +3,7 @@ #include "ofMain.h" #include "ofxOpenCv.h" +#include "ofxRay.h" //#define _USE_LIVE_VIDEO // uncomment this to use a live camera // otherwise, we'll use a movie file @@ -43,6 +44,13 @@ class testApp : public ofBaseApp{ float cam_angle; + ofCamera cam; + + ofRay ray; + ofPlane plane; + ofProjector projector; + + ofVec3f pos; }; |
