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.
Page Index Toggle Pages: 1
Sending an OSC signal to pd (Read 3124 times)
Sending an OSC signal to pd
May 22nd, 2009, 1:47pm
 
Hi,

I want to send a signal from Processing to PureData via OSC. I work with face detection (that works now) and I want to send a "1" if a face is detected and a "0" if there is no face. I thought it would be the easiest way. I searched for examples, but I never worked with OSC and I am not a Processing-hero.. so I need help.

I started with this code:
Code:
import pFaceDetect.*;
import JMyron.*;
import oscP5.*;
import netP5.*;

PFaceDetect face;
JMyron m;
PImage img;


void setup() {
size(320,240);
m = new JMyron();
m.start(width,height);
m.findGlobs(0);
face = new PFaceDetect(this,width,height,
"haarcascade_frontalface_default.xml");
frameRate(15);
img = createImage(width,height,ARGB);
rectMode(CORNER);
noFill();
stroke(255,0,0);
smooth();
}

void draw() {
background(0);
m.update();
arraycopy(m.cameraImage(),img.pixels);
img.updatePixels();
face.findFaces(img);
image(img,0,0);
drawFace();
}

void drawFace() {
int [][] res = face.getFaces();
if (res.length>0) {
for (int i=0;i<res.length;i++) {
int x = res[i][0];
int y = res[i][1];
int w = res[i][2];
int h = res[i][3];
rect(x,y,w,h);
}
}
}

void oscEvent(OscMessage message){
if (res.length>0) {
// I don`t know what I have to write here...
}
}

void stop() {
m.stop();
super.stop();
}

That´s a face detection example from "bryanchung.net/?page_id=251" with an addition of the OSC protocol, but I don`t know how to go on.

I hope this is the write place to post my question.
I am sorry, that I have not a hugh knowledge about the osc, but I havn´t understand the examples for OSC in processing.

Thanks a lot for help,
Anna
Re: Sending an OSC signal to pd
Reply #1 - May 23rd, 2009, 6:17pm
 
Hey-

So I think your problem is the function oscEvent is triggered when there is an incoming message via osc. What you want to do is just send an osc message to pd. To do that you need to do something like:

Code:

NetAddress remote;
OscP5 oscP5;

void setup() {
 oscP5 = new OscP5(this,12000);
 remote = new NetAddress(127.0.0.1,1234);
}

void draw() {
 OscMessage msg = new OscMessage("/faceRecog/status");
 msg.add("found face");
 oscP5.send(msg,remote);
}


Then you just need a pd patch that can parse data from osc.

Hope that helps,
Adam
Re: Sending an OSC signal to pd
Reply #2 - May 24th, 2009, 4:07am
 
Thanks a lot!
With your help (and more hours spending with google) I solved the problem.

Code:
import pFaceDetect.*;
import JMyron.*;
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress remote;

PFaceDetect face;
JMyron m;
PImage img;


void setup() {
size(320,240);
m = new JMyron();
m.start(width,height);
m.findGlobs(0);
face = new PFaceDetect(this,width,height,
"haarcascade_frontalface_default.xml");
frameRate(15);
img = createImage(width,height,ARGB);
rectMode(CORNER);
noFill();
stroke(255,0,0);
smooth();
oscP5 = new OscP5(this,1234);
remote = new NetAddress("127.0.0.1",1234);
}

void draw() {
background(0);
m.update();
arraycopy(m.cameraImage(),img.pixels);
img.updatePixels();
face.findFaces(img);
image(img,0,0);
drawFace();

int [][] res = face.getFaces();
OscMessage myOscMessage = new OscMessage("/test");
if (res.length>0) {
myOscMessage.add(1);
oscP5.send(myOscMessage, remote);
}
else {
myOscMessage.add(0);
oscP5.send(myOscMessage, remote);
}

}

void drawFace() {
int [][] res = face.getFaces();
if (res.length>0) {
for (int i=0;i<res.length;i++) {
int x = res[i][0];
int y = res[i][1];
int w = res[i][2];
int h = res[i][3];
rect(x,y,w,h);
}
}
}

void stop() {
m.stop();
super.stop();
}


But I did not find in the internet that the oscEvent is only for recieving. Thanks for the idea to put this in the draw method!

Thx,
Anna
Re: Sending an OSC signal to pd
Reply #3 - May 28th, 2009, 1:19pm
 
Hi,

Does anyone know where I can find the netP5 library that goes with "import netP5.*;"?

Thanks.

MMIX

Re: Sending an OSC signal to pd
Reply #4 - May 28th, 2009, 11:13pm
 
hi, the netP5 library is included in the oscP5 package. when including a library using the menubar-items sketch->import library->oscP5 the package netP5 will be imported together with package oscP5.
(this should answer the same question posted in another post, too.)
best,
andreas

Page Index Toggle Pages: 1