Hello everybody,
Im a artist and new to processing en coding in general.
Im trying to make a code that captures a image of a face and use that to make a dynamic Image composed of the faces that watches it.
it uses Opencv face detection to detect the face. and it uses a midi controller to output to a external program for sound.
Ive been merging different liberaries en trying to make the code work. So far ive managed to place copies of faces on top of the image.
I want the images to stack on top of each other. The entire screen should fill up with different images of faces depending on who watching where in the screen. I tried switching places in the draw section, but cant get it to work. please take a look at the code and help me to fix it! Or maybe i should approach this in a other way. Any feedback will help!
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
import themidibus.*;
PImage img;
PImage saveImage;
PImage partialSave;
MidiBus myBus;
Capture video;
OpenCV opencv;
void setup() {
size (640, 480);
frameRate(15);
MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
myBus = new MidiBus(this, -1, 3);
video = new Capture(this, 640, 480);
opencv = new OpenCV(this, 640, 480);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
loadPixels();
updatePixels();
img = loadImage("FaceSnap.jpg");
video.start();
}
void draw() {
opencv.loadImage(video);
Rectangle[] faces = opencv.detect();
println(faces.length);
for (int i = 0; i < faces.length; i++) {
println(faces[i].x + "," + faces[i].y);
float valuex = faces[i].x;
myBus.sendControllerChange(1, 20,int(valuex)); // Send a controllerChange
float valuey = faces[i].y;
myBus.sendControllerChange(1, 21,int(valuey)); // Send a controllerChange
float valuez = faces[i].width; //extra controller
float valueq = faces[i].height; //extra controller
partialSave = get(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
partialSave.save("FaceSnap.jpg");
background(0,0,0);
image(video,0,0);
image (img, valuex, valuey);
img = loadImage("FaceSnap.jpg");
}
}
void captureEvent(Capture c) {
c.read();
}