我正在尝试在JavaCV中实现EigenFace Recognition并通过以下代码实现它: -
public static void main(String[] args) {
String trainingDir = "C:/Users/user/Documents/NetBeansProjects/Face/testimg";
IplImage testImage = cvLoadImage("C:/Users/user/Desktop/aa.png");
File root = new File(trainingDir);
FilenameFilter pngFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".png");
}
};
File[] imageFiles = root.listFiles(pngFilter);
MatVector images = new MatVector(imageFiles.length);
int[] labels = new int[imageFiles.length];
int counter = 0;
int label;
IplImage img;
IplImage grayImg = null;
try {
for (File image : imageFiles) {
img = cvLoadImage(image.getAbsolutePath(), CV_BGR2GRAY);
int yer = image.getName().indexOf(".");
String isim = image.getName().substring(0, yer);
label = Integer.parseInt(isim);
images.put(counter, img);
labels[counter] = label;
counter++;
}
} catch (Exception e) {
e.printStackTrace();
}
IplImage greyTestImage = IplImage.create(testImage.width(), testImage.height(), IPL_DEPTH_8U, 1);
//FaceRecognizer faceRecognizer = createFisherFaceRecognizer();
FaceRecognizer faceRecognizer = createEigenFaceRecognizer();
//FaceRecognizer faceRecognizer = createLBPHFaceRecognizer()
faceRecognizer.train(images, labels);
cvCvtColor(testImage, greyTestImage, CV_BGR2GRAY);
int predictedLabel = faceRecognizer.predict(greyTestImage);
System.out.println("Predicted label: " + predictedLabel);
}
但是每次我运行它都会给我一个错误
OpenCV错误:图像步骤错误(矩阵不连续,因此其行数无法更改)在cv :: Mat :: reshape,file ........ \ opencv \ modules \ core \ src \ matrix.cpp,第802行 线程" main"中的例外情况java.lang.RuntimeException:........ \ opencv \ modules \ core \ src \ matrix.cpp:802:error:( - 13)矩阵不连续,因此其行数无法更改在函数cv :: Mat :: reshape
中
我已经阅读了一些在图像大小不同且不是8的倍数时发生的情况,但是我拥有相同大小和灰度级的所有图像。我用于保存检测到的面部的代码是: - < / p>
Mat image_roi = new Mat(frame,rect_Crop);
Imgproc.cvtColor(image_roi, image_roi, Imgproc.COLOR_BGR2GRAY);
Size sz = new Size(240,240);
Imgproc.resize( image_roi, image_roi, sz );
String filename = "testimg\\" +jTextField1.getText() + ".png";
System.out.println(String.format("Writing %s", filename));
Imgcodecs.imwrite(filename, image_roi);
它也给了我
java.lang.NumberFormatException:
我的文件不知道为什么..... ??? 请帮帮...... !!!!