Hey! So i have this assignement where i need to create a binary image of what my computer camera catches and when i have more than 100 white pixels it should appear a message saying motion detected. The problem is I don’t know how can i count the amount of white pixels that appear.
Any help would be so very appreciated
import processing.video.*;
Capture cam;
PImage diference;
PImage frameAnt;
PImage binary;
float threshold = 50;
float pxWhite = 100;
void setup () {
size(640, 240);
cam = new Capture(this, 320, 240);
diference = new PImage(320, 240);
frameAnt = new PImage(320, 240);
binary = new PImage(320, 240);
cam.start();
}
void draw () {
if (cam.available()) {
cam.read();
cam.loadPixels();
diference.loadPixels();
frameAnt.loadPixels();
binary.loadPixels();
for (int i = 0; i < cam.pixels.length; i++) {
float cR = red(cam.pixels[i]);
float cG = green(cam.pixels[i]);
float cB = blue(cam.pixels[i]);
float aR = red(frameAnt.pixels[i]);
float aG = green(frameAnt.pixels[i]);
float aB = blue(frameAnt.pixels[i]);
diference.pixels[i] = color(cR-aR, cG-aG, cB-aB);
float b = brightness(diference.pixels[i]);
if(b > threshold)
binary.pixels[i] = color(255);
else
binary.pixels[i] = color(0);
}
diference.updatePixels();
frameAnt = cam.copy();
binary.updatePixels();
}
image(cam, 0, 0);
image(binary, 320, 0);
}