Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

error when training SVM

i am new to such machine learning algorithm so ask if something is not clear and the error i am getting is

Exception in thread "main" java.lang.NullPointerException on this line s.setType(SVM.C_SVC);

   here is my code 

     Mat[] image = new Mat[2];
            image[0] = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/PLATES/1.jpg", 0);
            image[1] = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/PLATES/2.jpg", 0);
//        
        image[0] = image[0].reshape(0,1);
         image[1] = image[1].reshape(0,1);
            Mat img_mat = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/Dadcar3.png", 0);
            img_mat.reshape(0,1);


            Mat new_img = new Mat(2, 50367, CV_32FC1);


            float[] labels= {-1,1};
            Mat labelsmat = new Mat(2,1,CV_32FC1);
            labelsmat.convertTo(labelsmat, CV_32FC1);


            SVM s = null;
            s.setType(SVM.C_SVC);
            s.setKernel(SVM.LINEAR);
            s.setGamma(3);
            s.setDegree(3);
            s.train(new_img, 3, labelsmat);
            s.save("/home/tomna/NetBeansProjects/main/src/main/images.xml");
           s.predict(img_mat);
click to hide/show revision 2
retagged

updated 2017-02-09 18:49:34 -0600

berak gravatar image

error when training SVM

i am new to such machine learning algorithm so ask if something is not clear and the error i am getting is

Exception in thread "main" java.lang.NullPointerException on this line s.setType(SVM.C_SVC);

   here is my code 

     Mat[] image = new Mat[2];
            image[0] = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/PLATES/1.jpg", 0);
            image[1] = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/PLATES/2.jpg", 0);
//        
        image[0] = image[0].reshape(0,1);
         image[1] = image[1].reshape(0,1);
            Mat img_mat = Imgcodecs.imread("/home/tomna/NetBeansProjects/main/src/main/Dadcar3.png", 0);
            img_mat.reshape(0,1);


            Mat new_img = new Mat(2, 50367, CV_32FC1);


            float[] labels= {-1,1};
            Mat labelsmat = new Mat(2,1,CV_32FC1);
            labelsmat.convertTo(labelsmat, CV_32FC1);


            SVM s = null;
            s.setType(SVM.C_SVC);
            s.setKernel(SVM.LINEAR);
            s.setGamma(3);
            s.setDegree(3);
            s.train(new_img, 3, labelsmat);
            s.save("/home/tomna/NetBeansProjects/main/src/main/images.xml");
           s.predict(img_mat);