#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# How to make the ellipse stay on captured colour - video cam

edited January 2018

I want achive that with everz click on colour, there will appear and staz ellipse, capturing the colour/not to disappear. Is there some easier way than to create separate drawing loops for different ellipses? Just to say something like capture and stay, even if I click again somewhere else? (example from Levin and Shiffman)

import processing.video.*;

Capture video;

// A variable for the color we are searching for.
color trackColor;

void setup() {
size(640, 480);
video = new Capture(this, width, height);
video.start();
// Start off tracking black
trackColor = color(0);
}

void captureEvent(Capture video) {
// Read image from the camera
}

void draw() {
image(video, 0, 0);

//more higher more arger chance to find the colour
float worldRecord = 500;

// seek for the closest color
int closestX = 0;
int closestY = 0;

// search every pixel
for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height; y ++ ) {
int loc = x + y*video.width;
// define and showWhat is current color
color currentColor = video.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float b1 = blue(currentColor);
float r2 = red(trackColor);
float g2 = green(trackColor);
float b2 = blue(trackColor);

// Using euclidean distance to compare colors
float d = dist(r1, g1, b1, r2, g2, b2); // We are using the dist( ) function to compare the current color with the color we are tracking.

// If current color is more similar to tracked color than
// closest color, save current location and current difference
if (d < worldRecord) {
worldRecord = d;
closestX = x;
closestY = y;
}
}
}

// trackcolour not more far than 20
if (worldRecord < 20) {
// Draw a circle at the tracked pixel
fill(trackColor);
strokeWeight(4.0);
noStroke();
ellipse(closestX, closestY, 60, 60);
}
}

void mousePressed() {
// store the colour from video and keep it tracked
int loc = mouseX + mouseY*video.width;
trackColor = video.pixels[loc];
}
Tagged:

are you referring to line numbers 62 to 68 ?

• Yes. I wanted to create that everytime i click and create ellipse which is tracking the pixel colour, will stay there, tracking and I will with every click add a new one. thanks that you wrote.

• Some code:

class ColorTracker{
color col;
PVector p;

ColorTracker(float x, float y, color c){
col=c;
p=new Pvector(x,y);
}

void show(){
fill(col);
}
}

ArrayList<ColorTracker> points_Im_tracking= new ArrayList();

Repalce line 67 with: