analog
YaBB Newbies
Offline
Posts: 3
sending data from one tracking sketch to the other
Feb 2nd , 2009, 10:44pm
im working on a project, where im tracking an object and i need to send that data to another computer. ive used the networking server client sketches and adapted them so that they would work sending information back and forth on a single computer(well kinda, im getting an error when after the client sketch is loaded up for a few seconds to a minute the error is ArrayIndexOutOfBoundsException: 1. this error will vary on the different data ports so ill get same message, with the number changing to the different data ports) however im curious as to wheather i can even have the data write from one computer to another that way. any help would be greatly appreciated. ive put up the code that im working on, it is very messy i know im new to working with proccessing also im in the midst of getting things to work tracking server (this tracks the darkest pixel) /** * Brightness Tracking * by Golan Levin. * * Tracks the brightest pixel in a live video signal. */ import processing.video.*; import processing.net.*; Server s; Client c; String input; int data[]; Capture video; void setup() { size(720, 480, P3D); // Change size to 320 x 240 if too slow at 640 x 480 // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height, 60); stroke(0); //smooth(); s = new Server(this, 12345); // Start a simple server on a port } void draw() { if (video.available()) { video.read(); image(video, 0, 0, width, height); // Draw the webcam video onto the screen int brightestX = 0; // X-coordinate of the brightest video pixel int brightestY = 0; // Y-coordinate of the brightest video pixel float brightestValue = 0; // Brightness of the brightest video pixel // Search for the brightest pixel: For each row of pixels in the video image and // for each pixel in the yth row, compute each pixel's index in the video //video.loadPixels(); int index = 0; for (int y = 0; y < video.height; y++) { for (int x = 0; x < video.width; x++) { // Get the color stored in the pixel int pixelValue = -video.pixels[index]; // Determine the brightness of the pixel float pixelBrightness = brightness(pixelValue); // If that value is brighter than any previous, then store the // brightness of that pixel, as well as its (x,y) location if (pixelBrightness > brightestValue) { brightestValue = pixelBrightness; brightestY = y; brightestX = x; } index ++; } } // Draw a large, yellow circle at the brightest pixel // color set R G B background (brightestX-465, brightestY-225, (brightestY/2)); fill(150); ellipse(brightestX, brightestY,50 ,50); // Draw our line //line(brightestX, brightestY, brightestX, brightestY); // Send mouse coords to other person s.write(brightestX + " " + brightestY + " " + brightestX + " " + brightestY +"\n"); } // Receive data from client c = s.available(); if (c != null) { input = c.readString(); input = input.substring(0, input.indexOf("\n")); // Only up to the newline data = int(split(input, ' ')); // Split values into an array // Draw line using received coords noStroke(); line(data[0], data[1], data[2], data[3]); } } client receiver /** * Shared Drawing Canvas (Client) * by Alexander R. Galloway. * * The Processing Client class is instantiated by specifying a remote * address and port number to which the socket connection should be made. * Once the connection is made, the client may read (or write) data to the server. * Before running this program, start the Shared Drawing Canvas (Server) program. */ import processing.video.*; import processing.net.*; Client c; String input; int data[]; int a = 0; int b = 0; int c1 = 0; int d = 0; void setup() { size(720, 480, P3D); background(0); frameRate(60); // Slow it down a little // Connect to the server's IP address and port // smooth(); c = new Client(this, "127.0.0.1", 12345); // Replace with your server's IP and port } void draw() { { // Send mouse coords to other person c.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n"); } // Receive data from server if (c.available() > 0) { input = c.readString(); data = int(split(input, ' ')); // Split values into an array // Draw line using received coords a = data [0]; b = data [1]; c1 = data [2]; d = data [3]; rotateY (20); rotateX (1); rotateZ (2); stroke(a,b,a,b/3); noFill(); ellipse(a, b, a, a); strokeWeight (a); //println(a); // println(b); // println(c1); //println(d); } }