Thanks for the response, here is what I have so far
- import processing.video.*;
- Capture cam;
- //colors to look for
- color trackColor;
- int colorCount=0;
- boolean click= false;
- void setup() {
- size(640, 480);
- String[] cameras = Capture.list();
- cam = new Capture(this, cameras[0]);
- cam.start();
- }
- void draw() {
- if (cam.available() == true) {
- cam.read();
- }
- image(cam, 0, 0);
- cam.loadPixels();
- if(click){
- for(int i = 0; i<cam.width*cam.height;i++){
- if( cam.pixels[i]==trackColor)
- {
- colorCount++;
- }
- if(i == (cam.width*cam.height)-1){
- println(colorCount); //get amount of pixels of this colour in the frame
- float colorRatio = (colorCount/(cam.width*cam.height))*100; //get ratio of colour in relation to image: (colorPixels/All the pixels) *100
- println(colorRatio); // always returns 0, not sure why.
- colorCount = 0;
- }
- }
- }
- cam.updatePixels();
- }
- void mousePressed(){
- color c = get(mouseX, mouseY);
- int loc = mouseX + mouseY*cam.width;
- trackColor = cam.pixels[loc];
- click = true;
- }
When I try to convert this to a ratio of all the pixels in the frame I always get 0, this could be a really rookie mistake on my side or something to do with floating point calculations. I have never really worked with so many decimal places before.
I also don't know if this is the most efficient way to do this whole operation either.
The other thing I could use your input on is how I would go about checking to see if a range of a specific colour is present.
My final goal is to have a whole bunch of red and green (for example) paddles and be able tell which color is more prominent which would correspond to the amount of paddles present in the image.
Oh and taking into account distance - i do understand that if some are closer they will take up more space.
really appreciate your help