SlideShare ist ein Scribd-Unternehmen logo
1 von 63
$ 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" //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; //
};
#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
}
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){
}
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){
}
#include "ofxVectorMath.h"
#include "ofxBox2d.h"

//ofxBox2dCircle                 CustomCircle
class CustomCircle : public ofxBox2dCircle {
public:
   void draw(); //
};
#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(); //
}
#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
};
#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
}
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
    }
}
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){
}
#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
};
#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
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();
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){
}
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){
}
#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
#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);
}
#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;
};
#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);
}
#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;
};
#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);
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);
}
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;

   }
}

...(   )...
#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;
};
#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){
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);
}
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;

   }
}

...(   )...
#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;
};
#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;
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);
}
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;

   }
}

...(   )...
Sbaw091013

Weitere ähnliche Inhalte

Was ist angesagt?

Program project khusus
Program project khususProgram project khusus
Program project khususkiuntoro
 
The Ring programming language version 1.6 book - Part 174 of 189
The Ring programming language version 1.6 book - Part 174 of 189The Ring programming language version 1.6 book - Part 174 of 189
The Ring programming language version 1.6 book - Part 174 of 189Mahmoud Samir Fayed
 
Gaztea Tech 2015: 4. GT Drawbot Control
Gaztea Tech 2015: 4. GT Drawbot ControlGaztea Tech 2015: 4. GT Drawbot Control
Gaztea Tech 2015: 4. GT Drawbot ControlSvet Ivantchev
 
Hacer una calculadora en Java y en Visual Basic
Hacer una calculadora en Java y en Visual BasicHacer una calculadora en Java y en Visual Basic
Hacer una calculadora en Java y en Visual BasicHumbertoWuwu
 
C++14 reflections
C++14 reflections C++14 reflections
C++14 reflections corehard_by
 
The Ring programming language version 1.8 book - Part 98 of 202
The Ring programming language version 1.8 book - Part 98 of 202The Ring programming language version 1.8 book - Part 98 of 202
The Ring programming language version 1.8 book - Part 98 of 202Mahmoud Samir Fayed
 
ບົດລາຍງານ Honda gl09
ບົດລາຍງານ Honda gl09ບົດລາຍງານ Honda gl09
ບົດລາຍງານ Honda gl09kesukei
 
Cómo crear una calculadora js jv-ng
Cómo crear una calculadora js jv-ngCómo crear una calculadora js jv-ng
Cómo crear una calculadora js jv-nggzuz sanchez
 
Como hacer una calculadora en java
Como hacer una calculadora en javaComo hacer una calculadora en java
Como hacer una calculadora en javaaldair fernandez
 
como hacer una Calculadora en java y visual basic
como hacer una Calculadora en java y visual basiccomo hacer una Calculadora en java y visual basic
como hacer una Calculadora en java y visual basicDYBA039
 

Was ist angesagt? (20)

Sbaw090630
Sbaw090630Sbaw090630
Sbaw090630
 
Program project khusus
Program project khususProgram project khusus
Program project khusus
 
The Ring programming language version 1.6 book - Part 174 of 189
The Ring programming language version 1.6 book - Part 174 of 189The Ring programming language version 1.6 book - Part 174 of 189
The Ring programming language version 1.6 book - Part 174 of 189
 
Gaztea Tech 2015: 4. GT Drawbot Control
Gaztea Tech 2015: 4. GT Drawbot ControlGaztea Tech 2015: 4. GT Drawbot Control
Gaztea Tech 2015: 4. GT Drawbot Control
 
Juego del gato
Juego del gatoJuego del gato
Juego del gato
 
Hacer una calculadora en Java y en Visual Basic
Hacer una calculadora en Java y en Visual BasicHacer una calculadora en Java y en Visual Basic
Hacer una calculadora en Java y en Visual Basic
 
C++14 reflections
C++14 reflections C++14 reflections
C++14 reflections
 
The Ring programming language version 1.8 book - Part 98 of 202
The Ring programming language version 1.8 book - Part 98 of 202The Ring programming language version 1.8 book - Part 98 of 202
The Ring programming language version 1.8 book - Part 98 of 202
 
Proyecto Final Android-SQLite
Proyecto Final Android-SQLiteProyecto Final Android-SQLite
Proyecto Final Android-SQLite
 
Notification in Android App (in tamil)
Notification in Android App (in tamil)Notification in Android App (in tamil)
Notification in Android App (in tamil)
 
Dsa 1
Dsa 1Dsa 1
Dsa 1
 
Info clasa
Info clasaInfo clasa
Info clasa
 
ບົດລາຍງານ Honda gl09
ບົດລາຍງານ Honda gl09ບົດລາຍງານ Honda gl09
ບົດລາຍງານ Honda gl09
 
1- Sourcecode Array
1- Sourcecode Array1- Sourcecode Array
1- Sourcecode Array
 
Cómo crear una calculadora js jv-ng
Cómo crear una calculadora js jv-ngCómo crear una calculadora js jv-ng
Cómo crear una calculadora js jv-ng
 
Clinica
ClinicaClinica
Clinica
 
Trabajo de programacion
Trabajo de programacionTrabajo de programacion
Trabajo de programacion
 
Como hacer una calculadora en java
Como hacer una calculadora en javaComo hacer una calculadora en java
Como hacer una calculadora en java
 
como hacer una Calculadora en java y visual basic
como hacer una Calculadora en java y visual basiccomo hacer una Calculadora en java y visual basic
como hacer una Calculadora en java y visual basic
 
Macro
MacroMacro
Macro
 

Mehr von Atsushi Tadokoro

「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望Atsushi Tadokoro
 
プログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめようプログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめようAtsushi Tadokoro
 
Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2Atsushi Tadokoro
 
coma Creators session vol.2
coma Creators session vol.2coma Creators session vol.2
coma Creators session vol.2Atsushi Tadokoro
 
Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1Atsushi Tadokoro
 
Interactive Music II Processingによるアニメーション
Interactive Music II ProcessingによるアニメーションInteractive Music II Processingによるアニメーション
Interactive Music II ProcessingによるアニメーションAtsushi Tadokoro
 
Interactive Music II Processing基本
Interactive Music II Processing基本Interactive Music II Processing基本
Interactive Music II Processing基本Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携Atsushi Tadokoro
 
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)Atsushi Tadokoro
 
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描くiTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描くAtsushi Tadokoro
 
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリメディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリAtsushi Tadokoro
 
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使うAtsushi Tadokoro
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2Atsushi Tadokoro
 
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得Atsushi Tadokoro
 
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3DプログラミングWebデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3DプログラミングAtsushi Tadokoro
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1Atsushi Tadokoro
 
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画するiTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画するAtsushi Tadokoro
 
Media Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替えMedia Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替えAtsushi Tadokoro
 

Mehr von Atsushi Tadokoro (20)

「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
 
プログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめようプログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめよう
 
Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2
 
coma Creators session vol.2
coma Creators session vol.2coma Creators session vol.2
coma Creators session vol.2
 
Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1
 
Interactive Music II Processingによるアニメーション
Interactive Music II ProcessingによるアニメーションInteractive Music II Processingによるアニメーション
Interactive Music II Processingによるアニメーション
 
Interactive Music II Processing基本
Interactive Music II Processing基本Interactive Music II Processing基本
Interactive Music II Processing基本
 
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
 
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
 
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
 
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描くiTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
 
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリメディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
 
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
 
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
 
Tamabi media131118
Tamabi media131118Tamabi media131118
Tamabi media131118
 
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3DプログラミングWebデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
 
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画するiTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
 
Media Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替えMedia Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替え
 

Sbaw091013

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. $ cd ~/Desktop/ $ svn checkout http://vanderlin.googlecode.com/svn/ trunk/ofxBox2d ofxBox2d
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. #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; // };
  • 17. #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 }
  • 18. 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){ }
  • 19. 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){ }
  • 20.
  • 21.
  • 22. #include "ofxVectorMath.h" #include "ofxBox2d.h" //ofxBox2dCircle CustomCircle class CustomCircle : public ofxBox2dCircle { public: void draw(); // };
  • 23. #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(); // }
  • 24. #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 };
  • 25. #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 }
  • 26. 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 } }
  • 27. 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){ }
  • 28.
  • 29.
  • 30. #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 };
  • 31. #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
  • 32. 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();
  • 33. 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){ }
  • 34. 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){ }
  • 35.
  • 36.
  • 37.
  • 38.
  • 39. #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
  • 40. #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); }
  • 41.
  • 42.
  • 43. #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; };
  • 44. #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); }
  • 45.
  • 46.
  • 47. #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; };
  • 48. #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);
  • 49. 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); }
  • 50. 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; } } ...( )...
  • 51.
  • 52.
  • 53. #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; };
  • 54. #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){
  • 55. 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); }
  • 56. 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; } } ...( )...
  • 57.
  • 58.
  • 59. #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; };
  • 60. #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;
  • 61. 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); }
  • 62. 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; } } ...( )...