Hi, so im working on a code where it will track a users face through the OpenCV library. At the moment the code works with a single image and will trace the users face. However when i add an Array to it to add a element of randomisation to the code it give me the Null Point Error. If you could take a look that be amazing.
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
//PImage img;
PImage [] imgArray = new PImage[5]; //image array
//PImage bg;
Capture video;
OpenCV opencv;
void setup() {
size(640, 480);
for (int i=1;i<imgArray.length; i++){ //Setting up Array (randomiser)
imgArray[i]=loadImage("photo" + i +".png");
}
//imgBack = loadImage("sea.png"); //background
//img = loadImage("photo1.png");
//img = loadImage ("photo2.png");
//img = loadImage("photo3.png");
//img = loadImage ("photo4.png");
//img = loadImage ("photo5.png");
//bg=loadImage ("sea.png");
video = new Capture(this, 640, 480);
opencv = new OpenCV(this, 640, 480);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
video.start();
}
void draw() {
//background (bg);
scale(2);
opencv.loadImage(video);
//image(imgBack,0,0);
//image(bg,0,0);
image(video, 0, 0 );
noFill();
stroke(0, 0, 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);
//image(img, faces[i].x, faces[i].y, faces[i].width,faces[i].height);
image(imgArray[i],faces[i].x,faces[i].y,faces[i].width,faces[i].height); //Calling Array Image
}
}
void captureEvent(Capture c) {
c.read();
}
//void mousePressed(){
//img(imgArray[(int)random(25)],0,0,width,height);
//}