Traumaproductions
YaBB Newbies
Offline
Posts: 8
B
Re: Frame Differencing with 2 camera's
Reply #1 - Feb 25th , 2008, 6:09pm
//Ok so a little update on the project //the first thing i want to do is to be able to sent the //video data over a net work using the network library named //shared canvas client/server //sample of protocol for the client ** * 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.net.*; Client c; String input; int data[]; void setup() { size(450, 255); background(204); stroke(0); frameRate(5); // Slow it down a little // Connect to the server's IP address and port c = new Client(this, "127.0.0.1", 12345); // Replace with your server's IP and port } void draw() { if (mousePressed == true) { // Draw our line stroke(255); line(pmouseX, pmouseY, mouseX, mouseY); // Send mouse coords to other person c.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n"); } // Receive data from server if (c.available() > 0) { 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 stroke(0); line(data[0], data[1], data[2], data[3]); } } //And now i dont want to sent a mouse movent over the //network but the input from the captured video from this //protocol * Frame Differencing * by Golan Levin. * * Quantify the amount of movement in the video frame using frame-differencing. */ import processing.video.*; int numPixels; int[] previousFrame; Capture video; void setup() { size(640, 480); // 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, 24); numPixels = video.width * video.height; // Create an array to store the previously captured frame previousFrame = new int[numPixels]; loadPixels(); } void draw() { if (video.available()) { // When using video to manipulate the screen, use video.available() and // video.read() inside the draw() method so that it's safe to draw to the screen video.read(); // Read the new frame from the camera video.loadPixels(); // Make its pixels[] array available int movementSum = 0; // Amount of movement in the frame for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame... color currColor = video.pixels[i]; color prevColor = previousFrame[i]; // Extract the red, green, and blue components from current pixel int currR = (currColor >> 16) & 0xFF; // Like red(), but faster int currG = (currColor >> 8) & 0xFF; int currB = currColor & 0xFF; // Extract red, green, and blue components from previous pixel int prevR = (prevColor >> 16) & 0xFF; int prevG = (prevColor >> 8) & 0xFF; int prevB = prevColor & 0xFF; // Compute the difference of the red, green, and blue values int diffR = abs(currR - prevR); int diffG = abs(currG - prevG); int diffB = abs(currB - prevB); // Add these differences to the running tally movementSum += diffR + diffG + diffB; // Render the difference image to the screen pixels[i] = color(diffR, diffG, diffB); // The following line is much faster, but more confusing to read //pixels[i] = 0xff000000 | (diffR << 16) | (diffG << 8) | diffB; // Save the current color into the 'previous' buffer previousFrame[i] = currColor; } // To prevent flicker from frames that are all black (no movement), // only update the screen if the image has changed. if (movementSum > 0) { updatePixels(); println(movementSum); // Print the total amount of movement to the console } } } //The question for now is how do i make the network protocol //sent the data from the frame differencing protocol over //the network? //Update: i also need to get the frame difference protocol to sent fullscreen tot the server //I'M REALY NEW TO PROCESSING AND REALY WOULD LINK SOME HELP ANYBOBY?