Skip to content

Instantly share code, notes, and snippets.

@behrooz-tahanzadeh
Last active February 9, 2017 11:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save behrooz-tahanzadeh/927e95ffac73b8e4327d to your computer and use it in GitHub Desktop.
import processing.video.*;
int numPixels;
float []previousFrame;
Capture cam;
float pixAverage;
void setup()
{
size(640, 480);
cam = new Capture(this, width, height);
cam.start();
numPixels = cam.width * cam.height;
previousFrame = new float[numPixels];
loadPixels();
stroke(0, 255, 255);
strokeWeight(4);
frameRate(10);
}
void draw()
{
if (cam.available())
{
cam.read();
cam.loadPixels();
int x = 0;
int y = 0;
int sum = 0;
for (int i = 0; i < numPixels; i++)
{
float currColor = red(cam.pixels[i]);
float prevColor = previousFrame[i];
float d = abs(prevColor-currColor);
if (d>50)
{
int xt = i % cam.width;
int yt = i / cam.width;
x += xt;
y += yt;
sum ++;
pixels[i] = color(currColor,0,0);
}
else
pixels[i] = color(currColor);
previousFrame[i] = currColor;
}
if (sum>1000)
{
updatePixels();
x /= sum;
y /= sum;
drawTarget(x,y);
}
}
}
void drawTarget(int x, int y)
{
line(x,y-15 , x,y-4);
line(x,y+15 , x,y+4);
line(x-15,y , x-4,y);
line(x+15,y , x+4,y);
}
@behnood-eghbali
Copy link

@behrooz-tahanzadeh nobody uses processing anymore! try reactVR! :)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment