$ cd ~/Desktop/

$ svn checkout http://vanderlin.googlecode.com/svn/
trunk/ofxBox2d ofxBox2d
#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"
#include "ofxVectorMath.h" //ofxVectorMath
#include "ofxBox2d.h" ...
#include "testApp.h"

void testApp::setup(){
  //
  ofSetVerticalSync(true);

  ofBackground(0, 0, 0);

    //Box2D
    bo...
void testApp::draw(){
  //circles

    for(int i=0; i<circles.size(); i++) {

    
      circles[i].draw();

    }

    //...
void testApp::mousePressed(int x, int y, int button){
  //
    float r = ofRandom(10, 40); //
    ofxBox2dCircle circle; /...
#include "ofxVectorMath.h"
#include "ofxBox2d.h"

//ofxBox2dCircle                 CustomCircle
class CustomCircle : publi...
#include "CustomCircle.h"

void CustomCircle::draw()
{
  float radius = getRadius(); //
    glPushMatrix(); //
    glTrans...
#ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofxVectorMath.h" //ofxVectorMath
#include "ofxBox2d.h" /...
#include "testApp.h"

void testApp::setup(){
  //
  ofSetVerticalSync(true);
  ofEnableAlphaBlending();
  ofSetCircleResol...
void testApp::draw(){
  //circles

       for(int i=0; i<circles.size(); i++) {

       
      circles[i].draw();

       ...
void testApp::keyReleased(int key){
}

void testApp::mouseMoved(int x, int y){
}

void testApp::mouseDragged(int x, int y,...
#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"
#include "ofxVectorMath.h" //ofxVectorMath
#include "ofxBox2d.h" ...
#include "testApp.h"

void testApp::setup(){
  //
  ofSetVerticalSync(true);
  ofEnableAlphaBlending();
  ofSetCircleResol...
r.setPhysics(1.0, 1.2, 0.5); //
        r.setup(box2d.getWorld(), x, y, w, h, true); //
        rects.push_back(r); //    ...
void testApp::keyPressed(int key){
  // c
    if (key == 'c') {
        float r = ofRandom(5, 20); //
         CustomCircl...
void testApp::mouseDragged(int x, int y, int button){
}

void testApp::mousePressed(int x, int y, int button){
}

void tes...
#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"
#include "ofxOpenCv.h"

class testApp : public ofBaseApp {

publi...
#include "testApp.h"

void testApp::setup(){
  ofBackground(0,0,0);

    vidGrabber.setVerbose(true);
    vidGrabber.initG...
#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"
#include "ofxOpenCv.h"

class testApp : public ofBaseApp {

publi...
#include "testApp.h"

void testApp::setup(){
  ofBackground(0, 0, 0);

    vidGrabber.setVerbose(true);
    vidGrabber.ini...
#ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofxOpenCv.h"

class testApp : public ofBaseApp {

public...
#include "testApp.h"

void testApp::setup(){
  ofBackground(0, 0, 0);
  ofEnableAlphaBlending();

    vidGrabber.setVerbos...
grayBg = grayImage;

   
        
     bLearnBakground = false;

   
        }
        grayDiff.absDiff(grayBg, grayImage)...
void testApp::keyPressed (int key){

   switch (key){

   
       case ' ':

   
       
     bLearnBakground = true;

   ...
#ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofxOpenCv.h"

class testApp : public ofBaseApp {
public:...
#include "testApp.h"

void testApp::setup(){
  ofBackground(0, 0, 0);
  ofEnableAlphaBlending();

    vidGrabber.setVerbos...
bLearnBakground = false;

   
         }
        grayDiff.absDiff(grayBg, grayImage);
        grayDiff.threshold(threshold...
void testApp::keyPressed (int key){

   switch (key){

   
      case ' ':

   
      
      bLearnBakground = true;

   
...
#ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofxOpenCv.h"

class testApp : public ofBaseApp {
public:...
#include "testApp.h"

void testApp::setup(){
  ofBackground(0, 0, 0);
  ofEnableAlphaBlending();

    vidGrabber.setVerbos...
grayDiff.absDiff(grayBg, grayImage);
        grayDiff.threshold(threshold);
        contourFinder.findContours(grayDiff, 2...
void testApp::keyPressed (int key){

   switch (key){

   
       case ' ':

   
       
     bLearnBakground = true;

   ...
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Sbaw091013
Upcoming SlideShare
Loading in …5
×

Sbaw091013

2,720 views
2,650 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,720
On SlideShare
0
From Embeds
0
Number of Embeds
821
Actions
Shares
0
Downloads
23
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Sbaw091013

    1. 1. $ cd ~/Desktop/ $ svn checkout http://vanderlin.googlecode.com/svn/ trunk/ofxBox2d ofxBox2d
    2. 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. 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. 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. 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. 6. #include "ofxVectorMath.h" #include "ofxBox2d.h" //ofxBox2dCircle CustomCircle class CustomCircle : public ofxBox2dCircle { public: void draw(); // };
    7. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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; } } ...( )...

    ×