Thanks a lot for your reply and clarifications.
Since I like the library so much , I am trying to use it further.
I am not being able to obtain any buttons in a sketch that involves video.
I am trying to find dice (blobs of color) on the table.
I tried to ad a slider for a treshold for instance but no buttons appear,
Code was generated in your gui tab.
Here is the main tab,
import processing.video.;
import java.awt.Font;
import g4p_controls.;
import java.awt.Font;
PFont f;
PFont font;
int w= #FFFFFF; // white
int y= #FCF442; //yellow
int g= #A0FFA3; //green
int b= #64E1FF; // blue
int m= #CC15D3; // Magenta
int o= #FF6C67; // orange
int i= #B767FF; // indigo
int r= #FC0B03; // red
int bk = (#212121);
Capture video;
color trackColor;
float threshold = 25;
int Wheel; // value from the mouse wheel
int WheelAcc=0; // mouse wheel accoumulated
void setup() {
size(1800, 1100, JAVA2D);
String[] cameras = Capture.list();
printArray(cameras);
video = new Capture(this, “name=iSight,size=640x480,fps=15”);
video.start();
trackColor = color(255, 0, 0);
font = loadFont(“AgencyFB-Bold-200.vlw”);
frameRate (15);
}
void captureEvent(Capture video) {
video.read();
}
void draw() {
background(bk);
video.loadPixels();
image(video, 0, 0);
//threshold = map(mouseX, 0, width, 0, 100);
threshold = 30+ WheelAcc;
threshold = constrain (threshold, 0, 100);
// /*
float avgX = 0;
float avgY = 0;
int count = 0; // nr of pixels found in
// 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);
float d = distSq(r1, g1, b1, r2, g2, b2);
if (d < threshold*threshold) {
stroke(255);
strokeWeight(1);
point(x, y); // this is replacing the "Found " pixels
avgX += x;
avgY += y;
count++;
}
}
}
// We only consider the color found if its color distance is less than 10.
// This threshold of 10 is arbitrary and you can adjust this number depending on how accurate you require the tracking to be.
if (count > 20) {
avgX = avgX / count;
avgY = avgY / count;
// Draw a circle at the tracked pixel
//println(avgX + " is avgX") ;
//println(avgY + " is avgY") ;
fill(255);
strokeWeight(4.0);
stroke(0);
ellipse(avgX, avgY, 24, 24);
}
else
{ //delay (100);
}
//fill (bk);
//rect(0, 700, 1760, 1060, 7);
fill (trackColor);
rect(10, 1040, 50, 1060, 7);
textFont(font, 35);
fill(w);
text(“trackColor= “, 70, 1090 );
text( trackColor, 240, 1090);
text(“RGB= “, 380, 1090 );
text(str(int(red(trackColor)))+”,”+str(int(green(trackColor)))+”,”+str(int(blue(trackColor))),460, 1090);
fill ®;
text(“avgX, AvgY:”, 10, 930 );
text( nf(avgX, 0, 1), 240, 930);
text( nf(avgY, 0, 1), 380, 930);
} // end of draw
float distSq(float x1, float y1, float z1, float x2, float y2, float z2)
{
float d = (x2-x1)(x2-x1) + (y2-y1)(y2-y1) +(z2-z1)*(z2-z1);
return d;
// */
}
void mousePressed() {
if (mouseButton == LEFT) { // Save color where the mouse is clicked in trackColor variable
int loc = mouseX + mouseY*video.width; // definition of location by pixel number.
trackColor = video.pixels[loc];
println(loc + " is loc") ;
println(trackColor + " is trackColor") ;
}
else if (mouseButton == RIGHT)
{video.read();
}
}
void mouseWheel(MouseEvent event) {
Wheel = event.getCount();
WheelAcc = WheelAcc + Wheel;
//println(WheelAcc + “Acc”) ;
//println(Wheel + “Wheel”) ;
println(threshold + " is Treshold") ;
Wheel = 0;
}