• fullscreen
  • web_upload.pde
  • import oscP5.*;
    import netP5.*;
    
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    
    float lhx, lhy, rhx, rhy, hx, hy; // coordinates
    float rex, rey, lex, ley, rfx, rfy;
    float lfx, lfy, rkx, rky, lkx, lky, tx, ty;
    
    
    void setup() {
    
      size(640, 480);
      frameRate(25);
      oscP5 = new OscP5(this, 12345);
    
      myRemoteLocation = new NetAddress("127.0.0.1", 12346);
    
    }
    
    
    void draw() {
      background(0); 
      sendData(); //refresh
      ellipse(hx, hy, 40, 60);
      fill(255, 50, 50);
      ellipse(lhx, lhy, 30, 30);
      fill(50, 50, 255);
      ellipse(rhx, rhy, 30, 30);
      stroke(255, 255, 255);
      
    
      ellipse(rex, rey, 30, 30);
      ellipse(lex, ley, 30, 30);
      ellipse(rfx, rfy, 20, 20);
      ellipse(lfx, lfy, 20, 20);
      ellipse(rkx, rky, 30, 30);
      ellipse(lkx, lky, 30, 30);
      ellipse(tx, ty, 30, 30);
      
      float d = dist(tx,ty,hx,hy);
      
      line(hx,hy+d/3,lex,ley);
      line(hx,hy+d/3,rex,rey);
      
      
      strokeWeight(2);
      line(lex,ley,lhx,lhy);
      line(rex,rey,rhx,rhy);
      line(hx,hy,tx,ty);
      line(tx,ty,rkx,rky);
      line(tx,ty,lkx,lky);
      line(lkx,lky,lfx,lfy);
      line(rkx,rky,rfx,rfy);
    
    
     
    }
    
    void sendData() {
    
      OscMessage myMessage = new OscMessage("/righthand_trackjointpos");
      OscMessage myMessage2 = new OscMessage("/lefthand_trackjointpos");
      OscMessage myMessage3 = new OscMessage("/head_trackjointpos");
      OscMessage myMessage4 = new OscMessage("/rightelbow_trackjointpos");
      OscMessage myMessage5 = new OscMessage("/leftelbow_trackjointpos");
      OscMessage myMessage6 = new OscMessage("/rightfoot_trackjointpos");
      OscMessage myMessage7 = new OscMessage("/leftfoot_trackjointpos");
      OscMessage myMessage8 = new OscMessage("/rightknee_trackjointpos");
      OscMessage myMessage9 = new OscMessage("/leftknee_trackjointpos");
      OscMessage myMessage10 = new OscMessage("/torso_trackjointpos");
    
    
    
    
      myMessage.add(3);
      myMessage2.add(3);
      myMessage3.add(3);
      myMessage4.add(3);
      myMessage5.add(3);
      myMessage6.add(3);
      myMessage7.add(3);
      myMessage8.add(3);
      myMessage9.add(3);
      myMessage10.add(3);
    
    
    
    
      oscP5.send(myMessage, myRemoteLocation); 
      oscP5.send(myMessage2, myRemoteLocation); 
      oscP5.send(myMessage3, myRemoteLocation);
      oscP5.send(myMessage4, myRemoteLocation); 
      oscP5.send(myMessage5, myRemoteLocation); 
      oscP5.send(myMessage6, myRemoteLocation);
      oscP5.send(myMessage7, myRemoteLocation); 
      oscP5.send(myMessage8, myRemoteLocation); 
      oscP5.send(myMessage9, myRemoteLocation);
      oscP5.send(myMessage10, myRemoteLocation);
    }
    
    
    /* incoming osc message. */
    void oscEvent(OscMessage theOscMessage) {
      // print("### received an osc message."+theOscMessage);
      //print(" addrpattern: "+theOscMessage.addrPattern());
      // println(" typetag: "+theOscMessage.typetag());
    
      String v=theOscMessage.addrPattern();
    
    
    
      if (v.equals("/righthand_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        rhx=x;
        rhy=y;
      }
    
      if (v.equals("/lefthand_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        lhx=x;
        lhy=y;
      }
    
      if (v.equals("/head_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        hx=x;
        hy=y;
      }
    
      if (v.equals("/rightelbow_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        rex=x;
        rey=y;
      }
    
      if (v.equals("/leftelbow_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        lex=x;
        ley=y;
      }
    
      if (v.equals("/rightfoot_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        rfx=x;
        rfy=y;
      }
    
      if (v.equals("/leftfoot_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        lfx=x;
        lfy=y;
      }
    
      if (v.equals("/rightknee_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        rkx=x;
        rky=y;
      }
    
      if (v.equals("/leftknee_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        lkx=x;
        lky=y;
      }
    
      if (v.equals("/torso_pos_screen")) {
        float x = theOscMessage.get(0).floatValue();  
        float y = theOscMessage.get(1).floatValue();
        tx=x;
        ty=y;
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    James Dyer

    Kinect in Processing

    Add to Faves Me Likey@! 3
    You must login/register to add this sketch to your favorites.

    you will need to download SYNAPSE

    (http://synapsekinect.tumblr.com/)

    and have the OSC library installed for processing

    (http://www.sojamo.de/libraries/oscP5/index.html)

    And you are ready to go, all this sketch does is take the OSC input data, and map it to some circles and lines. Just to show what kind of data it takes in.

    chris
    28 Aug 2011
    Hi,

    nice work!

    I tried out your sketch but it didn't work :(
    I added a print-advices in processing to look for what osc-message is coming from Synapse.

    -OscMessage----------
    received from /127.0.0.1:53616
    addrpattern /torso
    typetag s
    [0] forward


    So, instead of x,y,z coordinates, I get only a direction from the body part
    Can somebody help me with my problem?

    I would appreciate some answers.

    greetz
    chris
    James Dyer
    28 Aug 2011
    Hi Chris, I'm not too sure what your problem is, but this might help.

    String v=theOscMessage.addrPattern();

    if (v.equals("/righthand_pos_screen")) {
    float x = theOscMessage.get(0).floatValue();
    float y = theOscMessage.get(1).floatValue();
    rhx=x;
    rhy=y;
    }
    chris
    29 Aug 2011
    Hi James,

    thank you for your quick answer.

    I will explain my problem a bit more detailed:

    I copied the web_upload-Sketch from you in a new processing sketch. Added the oscP5-Library and plugged on my kinect. I'm expected that the circles get the position of the joints. I pushed the run-button, calibrated in synapse but nothing happened. So i added in the oscEvent-method of your sketch an print-advice (see 2), which delivered me the OscMessages coming from Synapse. The advice lists up all incoming oscMessages in the console. So i got a lot of the following Messages for several joints:

    -OscMessage----------
    received from /127.0.0.1:53616
    addrpattern /torso
    typetag s
    [0] forward

    Every time I move in front of the kinect i get a new Message like the one above. But the confusing about that is, that these oscMessages contain only one value. It's only a value for the direction as you can see in the code above (= forward). Usually there have to be more values including the x,y,z, coordinates, right?

    The code you posted, is actually in your sketch included and I run the sketch with it. So i can't understand why it didn't work.

    I managed the OpenNI thing and there was also a print()-advice in the OscEvent-method of the processing-examples from osceleton which delivered me something like that:

    ---------------------
    -OscMessage----------
    received from /127.0.0.1:62365
    addrpattern /joint
    typetag sifff
    [0] l_hip <-- Joint
    [1] 1
    [2] 0.59126383 <-- x
    [3] 0.608591 <-- y
    [4] 0.35033232 <-- z

    I can't explain why your sketch doesn't run on my mac?

    Do you use only Synapse and Processing or is there some MaxMSP or something like that in the pipeline?
    Which version of OS X do you use? I use 10.6.8.


    2)
    void oscEvent (OscMessage theOscMessage){

    theOscMessage.print();
    ...
    ...
    ...
    }

    I would appreciate your help.

    Greez
    chris
    James Dyer
    29 Aug 2011
    Heya Chris, I have a feeling I know whats wrong with it, I will have a look about when I get back from work. feel free to email me at jms.dyer@gmail.com in future. This shouldn't be too much work :)
    James Dyer
    30 Aug 2011
    for anyone with an issue with this example, I apologies, here is a link to an example file for processing http://www.mediafire.com/file/0g8q8azmm1y11mq/kinect_fix.zip
    Ankkit Modi
    2 Apr 2012
    you got the code for the laseres+ableton up? or is this the one?
    James Dyer
    3 Apr 2012
    Hi Ankkit, I do not have the code for it but I can talk you through the process of it via email. It involves an Arduino, Processing, Laser Pen and Light Sensor. You can email me on jms.dyer@gmail.com
    Daan de Lange
    5 Jun 2013
    Hey, thanks for your useful app :)
    I had an issue binding Processing to Synapse trough OSC and resolved it by changing port 12345 to port 12347 in the P5 sketch.
    You need to login/register to comment.