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 & HelpSound,  Music Libraries › Help with sending OSC P5 thing- processing to Pd
Page Index Toggle Pages: 1
Help with sending OSC P5 thing- processing to Pd (Read 1313 times)
Help with sending OSC P5 thing- processing to Pd
May 19th, 2010, 8:01am
 
Hello, I was wondering if anyone could help me.

I have a color detection patch in Processing that I want to communicate to Pure Data. I have downloaded the OSC P5 library. I just need to know how to set it up so the 2 communicate with each other. Like, what code to type into the Processing window.
I am pretty new with this stuff so you might have to speak slowly :)

thanks if anyone can help on this....

H
Re: Help with sending OSC P5 thing- processing to Pd
Reply #1 - May 19th, 2010, 8:38am
 
Oh, in case its any help, here is the troublesome patch:


import processing.video.*;
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;



Capture video;

int numPixels;                      // number of pixels in the video
int rectDivide = 4;                 // the stage width/height divided by this number is the video width/height
int vidW;                           // video width
int vidH;                           // video height
int[][] colouredPixels;             // the different colour references for each pixel
int[][] colourCompareData;          // captured r, g and b colours
int currR;                          //
int currG;                          //
int currB;                          //
int[][] squareCoords;               // x, y, w + h of the coloured areas
color[] colours;                    // captured colours
int colourRange = 25;               // colour threshold
int[][] centrePoints;               // centres of the coloured squares
color[] pixelColours;
boolean isShowPixels = false;       // determines whether the square and coloured pixels are displayed
int colourMax = 2;                  // max amount of colours - also adjust the amount of colours added to pixelColours in setup()
int coloursAssigned = 0;            // amount of cours currently assigned
CoordsCalc coordsCalc;

void setup()
{
 size(640, 480);
 vidW = width / rectDivide;
 vidH = height / rectDivide;
 video = new Capture(this, vidW, vidH, 30);
 noStroke();
 numPixels = vidW * vidH;
 colouredPixels = new int[vidH][vidW];
 colourCompareData = new int[colourMax][3];
 squareCoords = new int[colourMax][4];
 colours = new color[colourMax];
 centrePoints = new int[colourMax][2];
 color c1 = color(0, 255, 0);
 color c2 = color(255, 0, 0);
 pixelColours = new color[colourMax];
 pixelColours[0] = color(0, 255, 0);
 pixelColours[1] = color(255, 0, 0);
 coordsCalc = new CoordsCalc();
 
 oscP5 = new OscP5(this, 12000);
 myRemoteLocation = new NetAddress("127.0.0.1", 12000);
}

void captureEvent(Capture video)
{
 video.read();
}

void draw()
{
 noStroke();
 fill(255, 255, 255);
 rect(0, 0, width, height);
 drawVideo();
 coordsCalc.update();
 for (int i = 0; i < coloursAssigned; i++)
 {
   if (isShowPixels) drawSquare(i);
 }
}


void drawVideo()
{
 for (int i = 0; i < coloursAssigned; i++)
 {
   fill(colours[i]);
   rect(i * 10, vidH, 10, 10);
 }
 image(video, 0, 0);
 noFill();
 stroke(255, 0, 0);
 strokeWeight(2);
 rect(vidW - 4, vidH - 4, 4, 4);
}

void drawSquare(int i)
{
 int sqX = squareCoords[i][0];
 int sqY = squareCoords[i][1];
 int sqW = squareCoords[i][2];
 int sqH = squareCoords[i][3];
 noFill();
 stroke(0, 0, 255);
 strokeWeight(3);
 rect(sqX, sqY, sqW, sqH);

 //stroke(0, 0, 255);
 //strokeWeight(4);
 rect(sqX * rectDivide, sqY * rectDivide, sqW * rectDivide, sqH * rectDivide);
 line(sqX * rectDivide, sqY * rectDivide, ((sqX * rectDivide) + (sqW * rectDivide)), ((sqY * rectDivide) + (sqH * rectDivide)));
 line(((sqX * rectDivide) + (sqW * rectDivide)), sqY * rectDivide, sqX * rectDivide, (sqY * rectDivide + sqH * rectDivide));
}

void keyPressed()
{
 println("key pressed = " + key);
 color currPixColor = video.pixels[numPixels - (vidW * 2) - 3];
 int pixR = (currPixColor >> 16) & 0xFF;
 int pixG = (currPixColor >> 8) & 0xFF;
 int pixB = currPixColor & 0xFF;
 if (key == 'p')
 {
   isShowPixels = !isShowPixels;
 }
 if (key == '1')
 {
   coloursAssigned = 1;
   colourCompareData[0][0] = pixR;
   colourCompareData[0][1] = pixG;
   colourCompareData[0][2] = pixB;
   colours[0] = color(pixR, pixG, pixB);
 }
 if (colourMax < 2 || coloursAssigned < 1) return;
 if (key == '2')
 {
   coloursAssigned = 2;
   colourCompareData[1][0] = pixR;
   colourCompareData[1][1] = pixG;
   colourCompareData[1][2] = pixB;
   colours[1] = color(pixR, pixG, pixB);
 }
 if (key == '0')
 {
   coloursAssigned = 0;
 }
}
Page Index Toggle Pages: 1