1 | initial version |
if you train your SVM on HOG features, you need those for the prediction, too. (not the actual images)
public static void test() {
System.out.println("Testing..");
Mat img = Imgcodecs.imread(new File(FILE_TEST).getAbsolutePath(),0);
HOGDescriptor d = new HOGDescriptor(new Size(32, 16), new Size(8, 8), new Size(4, 4), new Size(4, 4), 9);
Mat descriptors = new Mat();
d.compute(img, descriptors);
System.out.println(clasificador.predict(descriptors.reshape(1,1)));
}
2 | No.2 Revision |
if you train your SVM on HOG features, you need those for the prediction, too. (not the actual images)
public static void test() {
System.out.println("Testing..");
Mat img = Imgcodecs.imread(new File(FILE_TEST).getAbsolutePath(),0);
HOGDescriptor d = new HOGDescriptor(new Size(32, 16), new Size(8, 8), new Size(4, 4), new Size(4, 4), 9);
Mat descriptors = new Mat();
d.compute(img, descriptors);
System.out.println(clasificador.predict(descriptors.reshape(1,1)));
}
last: please make sure, that your test images have the same size as your train images, so your hog descriptors have same size too, for train & test.