Sbaw091013

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Sbaw091013 - Presentation Transcript

    1. $ cd ~/Desktop/ $ svn checkout http://vanderlin.googlecode.com/svn/ trunk/ofxBox2d ofxBox2d
    2. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxVectorMath.h" //ofxVectorMath #include "ofxBox2d.h" //ofxBox2d class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofxBox2d box2d; //Box2D vector <ofxBox2dCircle> circles; // };
    3. #include "testApp.h" void testApp::setup(){ // ofSetVerticalSync(true); ofBackground(0, 0, 0); //Box2D box2d.init(); //Box2D box2d.setGravity(0,5); // 5 box2d.createBounds(0, 0, ofGetWidth(), ofGetHeight()); // box2d.setFPS(30); //30fps } void testApp::update(){ box2d.update(); //Box2D }
    4. void testApp::draw(){ //circles for(int i=0; i<circles.size(); i++) { circles[i].draw(); } //Box2D box2d.draw(); } void testApp::keyPressed(int key){ } void testApp::keyReleased(int key){ } void testApp::mouseMoved(int x, int y){ } void testApp::mouseDragged(int x, int y, int button){ }
    5. void testApp::mousePressed(int x, int y, int button){ // float r = ofRandom(10, 40); // ofxBox2dCircle circle; //ofxBox2dCircle( ) circle.setPhysics(1.0, 0.8, 0.5); // ( ) circle.setup(box2d.getWorld(), mouseX, mouseY, r); // circles.push_back(circle); // circles } void testApp::mouseReleased(int x, int y, int button){ } void testApp::windowResized(int w, int h){ }
    6. #include "ofxVectorMath.h" #include "ofxBox2d.h" //ofxBox2dCircle CustomCircle class CustomCircle : public ofxBox2dCircle { public: void draw(); // };
    7. #include "CustomCircle.h" void CustomCircle::draw() { float radius = getRadius(); // glPushMatrix(); // glTranslatef(getPosition().x, getPosition().y, 0); // ofFill(); // ofSetColor(31,127,255,100); // 1 ofCircle(0, 0, radius); // 1 ofSetColor(31,127,255,200); // 2 ofCircle(0, 0, radius*0.7); // 2 glPopMatrix(); // }
    8. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxVectorMath.h" //ofxVectorMath #include "ofxBox2d.h" //ofxBox2d #include "CustomCircle.h" //CustomCircle class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofxBox2d box2d; //Box2D vector <CustomCircle> circles; //CustomCircle };
    9. #include "testApp.h" void testApp::setup(){ // ofSetVerticalSync(true); ofEnableAlphaBlending(); ofSetCircleResolution(64); ofBackground(0, 0, 0); //Box2D box2d.init(); //Box2D box2d.setGravity(0,5); // 5 box2d.createBounds(0, 0, ofGetWidth(), ofGetHeight()); // box2d.setFPS(30); //30fps } void testApp::update(){ box2d.update(); //Box2D }
    10. void testApp::draw(){ //circles for(int i=0; i<circles.size(); i++) { circles[i].draw(); } //Box2D box2d.draw(); } void testApp::keyPressed(int key){ // c if (key == 'c') { float r = ofRandom(5, 20); // CustomCircle c; //CustomCircle c.setPhysics(1.0, 0.8, 0.5); // c.setup(box2d.getWorld(), mouseX, mouseY, r); // circles.push_back(c); // circles } }
    11. 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){ } void testApp::windowResized(int w, int h){ }
    12. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxVectorMath.h" //ofxVectorMath #include "ofxBox2d.h" //ofxBox2d #include "CustomCircle.h" //CustomCircle class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofxBox2d box2d; //Box2D vector <CustomCircle> circles; //CustomCircle vector <ofxBox2dRect> rects; // ofxBox2dRect };
    13. #include "testApp.h" void testApp::setup(){ // ofSetVerticalSync(true); ofEnableAlphaBlending(); ofSetCircleResolution(64); ofBackground(0, 0, 0); //Box2D box2d.init(); //Box2D box2d.setGravity(0,5); // 5 box2d.createFloor(); box2d.checkBounds(false); box2d.setFPS(30); //30fps // for (int i=0; i<100; i++) { //100 ofxBox2dRect r; //ofxBox2dRect( ) r float w = 2; // 2 float h = 2; // 2 float x = ofRandom(50, ofGetWidth()-50); // x
    14. r.setPhysics(1.0, 1.2, 0.5); // r.setup(box2d.getWorld(), x, y, w, h, true); // rects.push_back(r); // rects } } void testApp::update(){ box2d.update(); //Box2D } void testApp::draw(){ //circles for(int i=0; i<circles.size(); i++) { circles[i].draw(); } //rects for(int i=0; i<rects.size(); i++) { rects[i].draw(); } //Box2D box2d.draw();
    15. void testApp::keyPressed(int key){ // c if (key == 'c') { float r = ofRandom(5, 20); // CustomCircle c; //CustomCircle c.setPhysics(1.0, 0.8, 0.5); // c.setup(box2d.getWorld(), mouseX, mouseY, r); // circles.push_back(c); // circles } // r if (key == 'r') { for(int i=0; i<circles.size(); i++) { circles[i].destroyShape(); } circles.clear(); } } void testApp::keyReleased(int key){ } void testApp::mouseMoved(int x, int y){ }
    16. 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){ } void testApp::windowResized(int w, int h){ }
    17. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxOpenCv.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofVideoGrabber vidGrabber; ofxCvColorImage colorImg; }; #endif
    18. #include "testApp.h" void testApp::setup(){ ofBackground(0,0,0); vidGrabber.setVerbose(true); vidGrabber.initGrabber(320,240); colorImg.allocate(320,240); } void testApp::update(){ bool bNewFrame = false; vidGrabber.grabFrame(); bNewFrame = vidGrabber.isFrameNew(); if (bNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); } } void testApp::draw(){ colorImg.draw(20,20); }
    19. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxOpenCv.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofVideoGrabber vidGrabber; ofxCvColorImage colorImg; ofxCvGrayscaleImage grayImage; };
    20. #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); vidGrabber.setVerbose(true); vidGrabber.initGrabber(320,240); colorImg.allocate(320,240); grayImage.allocate(320,240); } void testApp::update(){ bool bNewFrame = false; vidGrabber.grabFrame(); bNewFrame = vidGrabber.isFrameNew(); if (bNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); grayImage = colorImg; } } void testApp::draw(){ ofSetColor(0xffffff); colorImg.draw(20,20); grayImage.draw(360,20); }
    21. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxOpenCv.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofVideoGrabber vidGrabber; ofxCvColorImage colorImg; ofxCvGrayscaleImage grayImage; ofxCvGrayscaleImage grayBg; ofxCvGrayscaleImage grayDiff; bool bLearnBakground; int threshold; };
    22. #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); ofEnableAlphaBlending(); vidGrabber.setVerbose(true); vidGrabber.initGrabber(320,240); colorImg.allocate(320,240); grayImage.allocate(320,240); grayBg.allocate(320,240); grayDiff.allocate(320,240); bLearnBakground = true; threshold = 100; } void testApp::update(){ bool bNewFrame = false; vidGrabber.grabFrame(); bNewFrame = vidGrabber.isFrameNew(); if (bNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels(), 320,240);
    23. grayBg = grayImage; bLearnBakground = false; } grayDiff.absDiff(grayBg, grayImage); grayDiff.threshold(threshold); } } void testApp::draw(){ ofNoFill(); ofSetColor(0xffffff); colorImg.draw(20,20); grayImage.draw(360,20); grayBg.draw(20,280); grayDiff.draw(360,280); ofSetColor(0xffffff); char reportStr[1024]; sprintf(reportStr, "threshold %i (press: +/-)", threshold); ofDrawBitmapString(reportStr, 20, 600); }
    24. void testApp::keyPressed (int key){ switch (key){ case ' ': bLearnBakground = true; break; case '+': threshold ++; if (threshold > 255) threshold = 255; break; case '-': threshold --; if (threshold < 0) threshold = 0; break; } } ...( )...
    25. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxOpenCv.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofVideoGrabber vidGrabber; ofxCvColorImage colorImg; ofxCvGrayscaleImage grayImage; ofxCvGrayscaleImage grayBg; ofxCvGrayscaleImage grayDiff; ofxCvContourFinder contourFinder; bool bLearnBakground; int threshold; };
    26. #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); ofEnableAlphaBlending(); vidGrabber.setVerbose(true); vidGrabber.initGrabber(320,240); colorImg.allocate(320,240); grayImage.allocate(320,240); grayBg.allocate(320,240); grayDiff.allocate(320,240); bLearnBakground = true; threshold = 100; } void testApp::update(){ bool bNewFrame = false; vidGrabber.grabFrame(); bNewFrame = vidGrabber.isFrameNew(); if (bNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); grayImage = colorImg; if (bLearnBakground == true){
    27. bLearnBakground = false; } grayDiff.absDiff(grayBg, grayImage); grayDiff.threshold(threshold); contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true); } } void testApp::draw(){ ofNoFill(); ofSetColor(0xffffff); colorImg.draw(20,20); grayImage.draw(360,20); grayBg.draw(20,280); grayDiff.draw(360,280); for (int i = 0; i < contourFinder.nBlobs; i++){ contourFinder.blobs[i].draw(360,540); } ofSetColor(0xffffff); char reportStr[1024]; sprintf(reportStr, "threshold %i (press: +/-)nnum blobs found %i", threshold, contourFinder.nBlobs); ofDrawBitmapString(reportStr, 20, 600); }
    28. void testApp::keyPressed (int key){ switch (key){ case ' ': bLearnBakground = true; break; case '+': threshold ++; if (threshold > 255) threshold = 255; break; case '-': threshold --; if (threshold < 0) threshold = 0; break; } } ...( )...
    29. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxOpenCv.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofVideoGrabber vidGrabber; ofxCvColorImage colorImg; ofxCvGrayscaleImage grayImage; ofxCvGrayscaleImage grayBg; ofxCvGrayscaleImage grayDiff; ofxCvContourFinder contourFinder; bool bLearnBakground; int threshold; };
    30. #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); ofEnableAlphaBlending(); vidGrabber.setVerbose(true); vidGrabber.initGrabber(320,240); colorImg.allocate(320,240); grayImage.allocate(320,240); grayBg.allocate(320,240); grayDiff.allocate(320,240); bLearnBakground = true; threshold = 100; } void testApp::update(){ bool bNewFrame = false; vidGrabber.grabFrame(); bNewFrame = vidGrabber.isFrameNew(); if (bNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); grayImage = colorImg; if (bLearnBakground == true){ grayBg = grayImage; bLearnBakground = false;
    31. grayDiff.absDiff(grayBg, grayImage); grayDiff.threshold(threshold); contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true); } } void testApp::draw(){ ofFill(); ofSetColor(0, 31, 255, 200); for( int i=0; i<(int)contourFinder.blobs.size(); i++ ) { ofBeginShape(); for( int j=0; j<contourFinder.blobs[i].nPts; j++ ) { ofVertex( contourFinder.blobs[i].pts[j].x * 4, contourFinder.blobs[i].pts[j].y * 4 ); } ofEndShape(); } ofSetColor(0xffffff); char reportStr[1024]; sprintf(reportStr, "threshold %i (press: +/-)nnum blobs found %i", threshold, contourFinder.nBlobs); ofDrawBitmapString(reportStr, 20, 10); }
    32. void testApp::keyPressed (int key){ switch (key){ case ' ': bLearnBakground = true; break; case '+': threshold ++; if (threshold > 255) threshold = 255; break; case '-': threshold --; if (threshold < 0) threshold = 0; break; } } ...( )...

    + Atsushi TadokroAtsushi Tadokro, 2 months ago

    custom

    226 views, 0 favs, 1 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 226
      • 120 on SlideShare
      • 106 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 2
    Most viewed embeds
    • 106 views on http://yoppa.org

    more

    All embeds
    • 106 views on http://yoppa.org

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?