Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

error : you need a real SVM instance , not a null pointer:

 SVM s = Ml.SVM.create();

error : your labelsmat does not have valid data, also rather make it int initially:

 int[] labels= {-1,1};
 Mat labelsmat = new Mat(2,1,CV_32SC1);
 labelsmat.put(0,0,labels);

error: your traindata is invalid, too ! you load 2 images, but never use them, it should rather look like:

 Mat traindata = new Mat();

 Mat image0 = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/PLATES/1.jpg", 0);
 traindata.push_back(image0.reshape(0,1));

 Mat image1 = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/PLATES/2.jpg", 0);
 traindata.push_back(image1.reshape(0,1));

 traindata.convertTo(traindata, CvType.CV_32F);
 // then, 50k features per row is probably a bit too much...

error : invalid flag in train(), this should be ROW_SAMPLES (0):

 s.train(traindata, 0, labelsmat);

error : if you want to predict many rows at a time (2 in your case), you need to supply a result Mat to predict()

(since it it can return only 1 value):

 Mat result = new Mat();
 s.predict(img_mat, result);
 System.out.println(result.dump());

good luck !

error : you need a real SVM instance , not a null pointer:

 SVM s = Ml.SVM.create();

error : your labelsmat does not have valid data, also rather make it int initially:

 int[] labels= {-1,1};
 Mat labelsmat = new Mat(2,1,CV_32SC1);
 labelsmat.put(0,0,labels);

error: your traindata is invalid, too ! you load 2 images, but never use them, it should rather look like:

 Mat traindata = new Mat();

 Mat image0 = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/PLATES/1.jpg", 0);
 traindata.push_back(image0.reshape(0,1));

 Mat image1 = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/PLATES/2.jpg", 0);
 traindata.push_back(image1.reshape(0,1));

 traindata.convertTo(traindata, CvType.CV_32F);
 // then, 50k features per row is probably a bit too much...

error : invalid flag in train(), this should be ROW_SAMPLES (0):

 s.train(traindata, 0, labelsmat);

error : if you want to predict many rows at a time (2 in your case), you need to supply a result Mat to predict()

(since it it can return only 1 value):

 Mat result = new Mat();
 s.predict(img_mat, s.predict(traindata, result);
 System.out.println(result.dump());

good luck !