We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Sending x,y ellipse coords with OSC
Page Index Toggle Pages: 1
Sending x,y ellipse coords with OSC (Read 1851 times)
Sending x,y ellipse coords with OSC
Oct 29th, 2006, 9:02am
 
Hi,

I've checked all the board about this question, i wasn't able to find any topic related to..

I try to send an ellipse (blob) coordinates with oscp5 but i can't find any information on how to...

here is the code i try to test :

Quote:
import processing.video.*;
import oscP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
           
           Capture video;
           
           float targetRed = 255.0; //set some numbers for the target you are chasing
           float targetGreen = 0.0;
           float targetBlue = 0.0;
           
           void setup()
           {
             video = new Capture(this, 360, 288, 12);
             size(360, 288);
           oscP5 = new OscP5(this,57121);
           myRemoteLocation = new NetAddress("127.0.0.1",57120);
           }
           
           void captureEvent(Capture camera)
           {
             camera.read();
           }
           
           void draw()
           {
            float worldRecord = 1000.0; //intialize the worldrecord
            int xFound = 0; // initialize the location of the green tracking dot
            int yFound = 0;

           loadPixels();
             for(int j=0; j < video.height; j=j+1) { //for each row
               for(int i=0; i < video.width; i=i+1) { //for each column
                 //get the color of this pixels
                 //find pixel in linear array using formula: pos = row*rowWidth+column
                 color pix = video.pixels[j*video.width+i];
                 //find the difference
                 float diff = abs(targetRed - red(pix)) + abs(targetGreen - green(pix)) + abs(targetBlue - blue(pix));
                 if (diff< worldRecord){ // if this is closest to our target color
                   worldRecord = diff;
                   yFound = j; //mark the spot for drawing it later
                   xFound = i;
                // println ("j="+j, "i="+i);
                println ("i"+i);
                 }
               }
             }
             image(video,0,0); //draw the video, this might be optional
             //after all the pixels have been tested, draw the winner
             fill(0,255,0);
             ellipse(xFound, yFound, 10, 10);            
         //  get(xFound, yFound);
        // println(xFound, yFound);
           }
         


void mousePressed() {
 OscMessage myMessage = new OscMessage("/null");
 myMessage.add(new int[] {yFound, xFound});
 oscP5.send(myMessage, myRemoteLocation);
}


when i check with println, i can see the coordinates in the console.

I would like to know/learn how to send both "yFound" and "xFound" values to osc

e.g:  sent together, separated with a coma.

Thx
Re: Sending x,y ellipse coords with OSC
Reply #1 - Oct 29th, 2006, 4:15pm
 
Well, one problem with your code, which is unrelated to OSC, is that xFound and yFound are local to draw() so they won't be defined in mousePressed().
Re: Sending x,y ellipse coords with OSC
Reply #2 - Oct 29th, 2006, 5:41pm
 
Hi,

Thx for your explanation.

How can i get these values to be sent with OscP5 ?

I tried to figure it out with no luck. Maybe it's to obvious that i can't see it... Smiley
Re: Sending x,y ellipse coords with OSC
Reply #3 - Oct 29th, 2006, 7:36pm
 
Thx a lot DDF, with the help of your post, i finally found the solution. Wink

I had to put it in void draw()

Quote:
OscMessage myMessage = new OscMessage("/null");
           myMessage.add(new int[] {xFound});


but, I'm still stuck with the message itself, i can't send both values (xFound and yFound with a coma in between) at the same time. (e.g:  4643,2386)
Re: Sending x,y ellipse coords with OSC
Reply #4 - Oct 29th, 2006, 10:19pm
 
hi  jaylfk,
i assume you are sending osc messages to supercollider according to port 57120 you are sending to. if so, you can use the OscResponder in sc to parse osc messages. then you also wouldnt need to have the comma in between the 2 values because you could easily parse the ints from the incoming message in sc. if you need the comma in between, i recommend sending your values as a string e.g.
Code:

OscMessage myMessage = new OscMessage("/null");
myMessage.add(yFound +"," + xFound});
oscP5.send(myMessage, myRemoteLocation);


in this case your osc message with address pattern /null would have the typetag s and one string value "4643,2386"

andi

Re: Sending x,y ellipse coords with OSC
Reply #5 - Oct 31st, 2006, 2:03pm
 
Hi Sojamo,

This is exactly what i wanted to do !

I'd like to thx you guys for all the effort you give to help people to create digital art.

I will later, post details about the project i am working on.

The last thing i'm working on is to be able to slowdown the osc message rate.

It is sending 25 msg/s, which is too much (8 would be enough)

I've got my localhost flooded by processing while sending OSC UDP messages to SC... and sometimes it even crash SC and/or the finder... (i'm working on mac).
Page Index Toggle Pages: 1