processing code in arduino?

Hi!

I’m new at arduino. I want to track movement with my arduino board by frame differencing with my iSight camera. In Processing it the code works. But I don’t get it into Arduino. Can someone help me?

This is the processing code:

// Code to quantify the amount of movement in the video frame 
// using a simple frame-differencing technique. 
import processing.video.*; 
int numPixels; 
int previousFrame[]; 
Capture video; 
void setup(){ 
  size(320, 240); 
  frameRate(30); //frameRate(30); 
  video = new Capture(this, width, height, 30); 
  numPixels = video.width * video.height; 
  // Create an array to store the previously captured frame   
  previousFrame = new int[numPixels]; 
} 
void captureEvent(Capture c) { 
  video.read(); 
} 
void draw() { 
  color currColor, prevColor;  // Current and previous pixels 
  int currR, currG, currB;     // Current color values 
  int prevR, prevG, prevB;     // Previous color values 
  int diffR, diffG, diffB;     // Computed differences 
  int movementSum = 0;         // Amount of movement in the frame 
  loadPixels(); //beginPixels(); 
  // For each pixel in the video frame... 
  for (int i=0; i<numPixels; i++){ 
    currColor = video.pixels[i];         
    prevColor = previousFrame[i]; 
    // Extract the red, green, and blue components from current pixel 
    currR = (currColor >> 16) & 0xFF;          
    currG = (currColor >> 8) & 0xFF;      
    currB =  currColor & 0xFF; 
    // Extract red, green, and blue components from previous pixel 
    prevR = (prevColor >> 16) & 0xFF;       
    prevG = (prevColor >> 8) & 0xFF;      
    prevB = prevColor & 0xFF; 
    // Compute the difference of the red, green, and blue values 
    diffR = abs(currR - prevR);  
    diffG = abs(currG - prevG);  
    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);     
    // Swap the current information into the previous. 
    previousFrame[i] = currColor;    
  } 
  updatePixels(); //endPixels(); 
  println(movementSum);  // Print out the total amount of movement 
}

At the end I want to visualize it with LEDs.

Thank you for helping!!

Arduino code runs on the Arduino board, using the little ATmega8 microcontroller. It’s not very powerful, and so Arduino can’t do nearly as many things as Processing. Actually, Arduino uses a different language (C/C++) than Processing (Java) - they just look similiar for basic things. You’ll need to use Processing (running on a computer) to process the camera image.

What you can do, however, is send data from Processing to the Arduino board over the USB connection using the Serial library. Then you can read that data with Arduino using its Serial functions and control the LEDs.

Thank you, I thought I just have to change some words in the code, now I try it like you told me!