...
Code Block | ||||
---|---|---|---|---|
| ||||
import processing.video.*; Capture video; color trackColor; void setup() { size(640, 480); // start video capture video = new Capture(this, width, height, 15); video.start(); // initialize track color to red trackColor = color(255, 0, 0); smooth(); } void draw() { // read video frame if available if (video.available()) { video.read(); } // load pixels video.loadPixels(); image(video, 0, 0 // draw video image(video, 0, 0); // initialize record to number greater than the diagonal of the screen float worldRecordrecord = 500; width+height; // initialize variable to store closest point intPVector closestXclosestPoint = new 0PVector(); int closestY = 0 // get track color as vector PVector trackColorVec = new PVector(red(trackColor), green(trackColor), blue(trackColor)); // go PVectorthrough closestPointimage =pixel new PVector(); by pixel for (int x=0; x < video.width; x++) { for (int y=0; y < video.height; y++) { // get pixel location int loc = x + y * video.width; // get pixel color color currentColor = video.pixels[loc];; // get current color as vector PVector currColorVec = new PVector(red(currentColor), green(currentColor), blue(currentColor)); PVector trackColorVec = new PVector(red(trackColor), green(trackColor), blue(trackColor)); // calculate distance between current color and track color float diffdist = currColorVec.dist(trackColorVec); // save point if closer than previous if (diffdist < worldRecordrecord) { worldRecordrecord = diffdist; closestPoint.x = x; closestPoint.y = y; } } } // draw point if (worldRecordwe found a one that is less than 10 apart if (record < 10) { fill(trackColor); strokeWeight(4.0); stroke(0); ellipse(closestPoint.x, closestPoint.y, 50, 50); } } void mousePressed() { // save color of current pixel under the mouse int loc = mouseX + mouseY * video.width; trackColor = video.pixels[loc]; } |
...