Here's the code i currently have, for some reason i keep getting back ArrayIndexOutOfBoundsException = 0; when in theory i thought replacing the faces[i].x in place of mouseX and faces[i].y in place of mouseY would make sense
Face Detect Squares
package ccpd.library;
int barWidth = 20;
int lastBar = -1;float max_distance;
import gab.opencv.;
import processing.video.;
import java.awt.*;Capture video;
OpenCV opencv;void setup() {
size(640, 480);
video = new Capture(this, 640/2, 480/2);
opencv = new OpenCV(this, 640/2, 480/2);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);video.start();
noStroke();
max_distance = dist(0, 0, width, height);
}void draw() {
background(0);
scale(2);
opencv.loadImage(video);image(video, 0, 0 );
noFill();
can remove square on face
stroke(0, 255, 0);
strokeWeight(3);
Rectangle[] faces = opencv.detect();
println(faces.length);for (int i = 0; i < faces.length; i++) {
println(faces[i].x + “,” + faces[i].y);
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
}
//to fill the squares with diff colour
int whichBar = mouseX / barWidth*2;
if (whichBar != lastBar) {
int barX = whichBar * barWidth;
// fill(mouseY, height, height);
stroke(0, 255, 0);
strokeWeight(3);
fill(mouseY, 0, 255);for (int i = 0; i <= width; i += 20) { for (int j = 0; j <= height; j += 20) { //float size = dist(mouseX, mouseY, i, j); //change from mouseX,mousyY to positions of the face? float size = dist(faces[i].x, faces[i].y, i, j); size = size/max_distance * 150; rect(i, j, size, size); } }
}
}void captureEvent(Capture c) {
c.read();
}
Just squares (working)
package ccpd.utilities;
int barWidth = 20;
int lastBar = -1;
float max_distance;
void setup() {
size(640, 360);
stroke(0, 255, 0);
strokeWeight(2);
max_distance = dist(0, 0, width, height);
// colorMode(HSB, height, height, height);
}
void draw() {
background(0);
//to fill the squares with diff colour
int whichBar = mouseY / barWidth*2;
if (whichBar != lastBar) {
int barX = whichBar * barWidth;
fill(mouseY, height, height);
fill(mouseY, 0, 255);
//the squares
for (int i = 0; i <= width; i += 20) {
for (int j = 0; j <= height; j += 20) {
float size = dist(mouseX, mouseY, i, j);
size = size/max_distance * 150;
rect(i, j, size, size);
}
}
}
}