The class should take the image and in the black pixels draw a rect of random color.
import processing.video.*;
Capture realTime;
ritrattoClass selfie;
PImage img;
void setup()
{
size(640,480);
background(0);
textSize(40);
text("Say Cheese and Press the Mouse", 5, width/3);
realTime= new Capture(this,640,480);
realTime.start();
loadPixels();
}
void captureEvent(Capture realTime)
{
realTime.read();
}
void draw()
{
//image(realTime,0,0);
if (mousePressed == true) {
realTime.stop();
img.filter(THRESHOLD);
image(img,0,0);
save("selfie.jpg");
selfie=new ritrattoClass(img);
selfie.ritratto();
}
}
void mousePressed() {
img=realTime.copy(); //saveFrame("selfie.jpg");
}
-----------Class-------------
class ritrattoClass{
PImage img;
PImage foto;
ritrattoClass(PImage foto){
img=foto;} //nel programma foto sarà una variabile con l'immagine "selfie"
void ritratto(){
foto.loadPixels();
for (int y=0; y<foto.height; y+=3)
{
for (int x=0; x<foto.width; x+=3)
{
int index = x+foto.width*y;
color col= foto.pixels[index];
if (col==0){
fill(random(255),random(255),random(255));
rect(x,y,3,3);
}
}
}
updatePixels();
}
}