Hi,
I know I ask a lot of question but this one really irritating me. I have googled a lot but couldn't find any solution.
Question is
I got a code from somewhere which can track any color picked from a video by mouse clicking and draw a ellipse filled with it. I want this is to use as tool to draw images over the video.
like here :
you will see video and graphics drawn over the video together
Code that I found is here :
- import processing.video.*;
- Capture video;
- color trackColor;
- void setup() {
- size(320, 240);
- video = new Capture(this, width, height, 15);
- trackColor = color(255, 0, 0);
- smooth();
- }
- void draw() {
- if (video.available()) {
- video.read();
- }
- video.loadPixels();
- image(video, 0, 0);
- float worldRecord = 500;
- int closestX = 0;
- int closestY = 0;
- for (int x = 0; x < video.width; x ++ ) {
- for (int y = 0; y < video.height; y ++ ) {
- int loc = x + y*video.width;
- 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);
- float d = dist(r1, g1, b1, r2, g2, b2);
- if (d < worldRecord) {
- worldRecord = d;
- closestX = x;
- closestY = y;
- }
- }
- }
- if (worldRecord < 10) {
- // Draw a circle at the tracked pixel
- fill(trackColor);
- strokeWeight(4.0);
- stroke(0);
- ellipse(closestX, closestY, 16, 16);
- }
- }
- void mousePressed() {
- int loc = mouseX + mouseY*video.width;
- trackColor = video.pixels[loc];
- }