so im building a drawing sketch where you draw with colour tracking (very original...)
but as im not having the video drawn on the stage your pretty much blind to as where your brush will paint.
so is there a simple solution to having either the cursor follow the tracked coordinates or have a ellipse follow it without being drawn onto the stage?
heres the code if it helps,
thanks in advance.
Neil
import processing.video.*; //camera Capture video; color trackColor; int[] xpos = new int[50]; int[] ypos = new int[50]; //camera
import controlP5.*; ControlP5 controlP5; int myColor = color(255,255,0); int StrokeSize = 10; ColorPicker cp; Textlabel myTextlabelA; Textlabel myTextlabelB; Textlabel myTextlabelC;
void setup() { size(640,480); frameRate(60); background(255); // load the custom cursor shape from svg cursorsvg = loadShape("cursor.svg");
controlP5 = new ControlP5(this); controlP5.addSlider("StrokeSize",01,120,60,10,80,100,100); // numbers minimum maximum default. then position. cp = controlP5.addColorPicker("picker",10,10,100,20); controlP5.setControlFont(new ControlFont(createFont("Verdana",8), 8)); myTextlabelA = controlP5.addTextlabel("label","HOLD DOWN SPACE TO DRAW",5,470); myTextlabelA.setColorValue(0xffcccccc); myTextlabelB = controlP5.addTextlabel("labelB","PRESS C TO CLEAR",5,450); myTextlabelB.setColorValue(0xffcccccc); myTextlabelC = controlP5.addTextlabel("labelC","PRESS S TO SAVE",5,430); myTextlabelC.setColorValue(0xffcccccc); //camera video = new Capture(this,width-1,height,60); // Start off tracking for red trackColor = color(102,255,255); //camera //camera for (int i = 0; i < xpos.length; i ++ ) { xpos[i] = 0; ypos[i] = 0; }} //camera void draw() { noStroke(); fill(75); rect(0,0,135,480); noStroke(); fill(cp.getColorValue()); ellipse(67,350,StrokeSize,StrokeSize); noStroke();
//camera // Capture and display the video if (video.available()) { video.read(); }
// Before we begin searching, the "world record" for closest color is set to a high number that is easy for the first pixel to beat. float worldRecord = 100;
// XY coordinate of closest color int closestX = 0; int closestY = 0;
// Begin loop to walk through every pixel for (int x = 0; x < video.width; x ++ ) { for (int y = 0; y < video.height; y ++ ) { int loc = (video.width - x - 1) + y*video.width; // What 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; } } }
// Shift array values for (int i = 0; i < xpos.length-1; i ++ ) { // Shift all elements down one spot. // xpos[0] = xpos[1], xpos[1] = xpos = [2], and so on. Stop at the second to last element. xpos[i] = xpos[i+1]; ypos[i] = ypos[i+1]; }
// New location xpos[xpos.length-1] = closestX; // Update the last spot in the array with the mouse location. ypos[ypos.length-1] = closestY;
Hi there,
new user here, just wondering if anyone could give me a clue how to either flip the horizontal axis
or flip the video input. here i have colour tracking code to move some snake code i found but its hard to feel it
when the video isnt flipped and ive just come to a block and cant seem to find a simple answer.
thanks if anyone can help me out it would be really appreciated.
-Neil
import processing.video.*;
Capture video; color trackColor; // Declare two arrays with 50 elements. int[] xpos = new int[50]; int[] ypos = new int[50];
void setup() { size(640,480);
video = new Capture(this,width,height,120);
// Start off tracking for red trackColor = color(102,255,255);
smooth();
// Initialize all elements of each array to zero. for (int i = 0; i < xpos.length; i ++ ) { xpos[i] = 0; ypos[i] = 0; } }
void draw() { background(255);
// Capture and display the video if (video.available()) { video.read();
}
// Before we begin searching, the "world record" for closest color is set to a high number that is easy for the first pixel to beat. float worldRecord = 110;
// XY coordinate of closest color int closestX = 0; int closestY = 0;
// Begin loop to walk through every pixel for (int x = 0; x < video.width; x ++ ) { for (int y = 0; y < video.height; y ++ ) { int loc = x + y*video.width; // What 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; } } }
// Shift array values for (int i = 0; i < xpos.length-1; i ++ ) { // Shift all elements down one spot. // xpos[0] = xpos[1], xpos[1] = xpos = [2], and so on. Stop at the second to last element. xpos[i] = xpos[i+1]; ypos[i] = ypos[i+1]; }
// New location xpos[xpos.length-1] = closestX; // Update the last spot in the array with the mouse location. ypos[ypos.length-1] = closestY;
// Draw everything for (int i = 0; i < xpos.length; i ++ ) { // Draw an ellipse for each element in the arrays. // Color and size are tied to the loop's counter: i. noStroke(); fill(trackColor-i*5); ellipse(xpos[i],ypos[i],i,i);