I've reviewed lots of questions related to my topic because of which i am able to understand that how this exception occurs but do not understand why this exception is occurring in the code i am executing. The class below takes two arguments:The path to the directory containing the training faces and the path to the image you want to classify. This is actually not my code it was written by Petter Christian Bjelland... Following is the code
public class OpenCVFaceRecognizer {
public static void main(String[] args) {
String trainingDir = args[0];
Object testImage = Highgui.imread(args[1], 0);
File root = new File(trainingDir);
FilenameFilter imgFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
name = name.toLowerCase();
return name.endsWith(".jpg") || name.endsWith(".pgm") || name.endsWith(".png");
}
};
File[] imageFiles = root.listFiles(imgFilter);
MatVector images = new MatVector(imageFiles.length);
Mat labels = new Mat(imageFiles.length, 1, CV_32SC1);
IntBuffer labelsBuf = labels.createBuffer();
int counter = 0;
for (File image : imageFiles) {
Object img = Highgui.imread(image.getAbsolutePath(), 0);
int label = Integer.parseInt(image.getName().split("\\-")[0]);
images.put(counter, (Mat) img);
labelsBuf.put(counter, label);
counter++;
}
FaceRecognizer faceRecognizer = createFisherFaceRecognizer();
faceRecognizer.train(images, labels);
int predictedLabel = faceRecognizer.predict((Mat) testImage);
System.out.println("Predicted label: " + predictedLabel);
}
}
Following is the complete exception
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at OpenCVFaceRecognizer.main(OpenCVFaceRecognizer.java:40)
This is the line 40 String trainingDir = args[0];