Image of microphone on track color pixel
in
Core Library Questions
•
2 years ago
Hello there,
I'm fairly new to processing and coding too. I want to make a prototype that can find the most blue pixel in the webcam image and draw an microphone on that pixel.
In the code i have now it draws an ellipse on the pixel.
I've tried it with vertex but it gives me error codes. Maybe one of you knows how to create the image on the pixel?
Thank you alot in advance!
Code:
I'm fairly new to processing and coding too. I want to make a prototype that can find the most blue pixel in the webcam image and draw an microphone on that pixel.
In the code i have now it draws an ellipse on the pixel.
I've tried it with vertex but it gives me error codes. Maybe one of you knows how to create the image on the pixel?
Thank you alot in advance!
Code:
import processing.video.*;
Capture cam;
color trackColor = color(0,0,255);;
int closest = 0;
int x = 0;
int y = 0;
void setup() {
size(320,240);
cam = new Capture(this,320,240);
}
void draw() {
if (cam.available()) {
cam.read();
}
cam.loadPixels();
float bestScore = 50000; // heel groot getal
for (int i = 0; i < cam.pixels.length; i ++ ) {
float distance = colorDist(cam.pixels[i], trackColor);
if (distance < bestScore) {
bestScore = distance;
closest = i;
}
}
image(cam,0,0);
fill(200,200,200);
x = closest % cam.width;
y = (closest - x) / cam.width;
ellipse(x,y,16,16);
fill(0,0,0);
rect(x,y,20,40);
}
void mousePressed() {
int loc = mouseX + mouseY*cam.width;
trackColor = cam.pixels[loc];
}
float colorDist(color c1, color c2){
return dist(red(c1), green(c1), blue(c1), red(c2), green(c2), blue(c2));
}
1