training my support vector machine?

asked 2017-02-06 13:10:09 -0600

Tomna gravatar image

updated 2017-02-06 13:11:14 -0600

i am trying to construct the training matrix before applying it to the SVM i read in this post (http://stackoverflow.com/questions/14...) that the matrix should be the number of images(rows) and their size(column ) in one matrix so my question is what if i have different sized images but same width and height and what to do about it and is the result correct to be used for SVM (as an output not logic) and here is my code and output

File file = new File("/home/tomna/NetBeansProjects/main/src/main/plates");
Mat training_mat= new Mat();
String[] images = new String[13];
Mat raw_img = new Mat();
for (int filenumber = 1; filenumber < 13; filenumber++) {

    String stream;
    stream = "/home/tomna/NetBeansProjects/main/src/main/cars" + "/" + filenumber + ".jpg";
    String fullfile = stream;
    images[filenumber] = fullfile;
}
for (int files = 1; files < 13; files++) {
    raw_img = Imgcodecs.imread(images[files]);
    if (!raw_img.empty()) {
        int Area = raw_img.width() * raw_img.height();
        System.out.println("succesfully loaded" + images[files] + "With size" + Area);
        int num_files = 12;
        training_mat = new Mat(files, Area, CvType.CV_32F);
    } else {
        System.out.println("Sorry error loading " + images[files]);
    }
}
Mat vec = training_mat.reshape(0,1);
System.out.println(vec.clone());

output

succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/1.jpg  With size83166
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/2.jpg  With size76800
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/3.jpg  With size607500
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/4.jpg  With size1920000
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/5.jpg  With size50246
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/6.jpg  With size513980
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/7.jpg  With size2359296
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/8.jpg  With size230400
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/9.jpg  With size406272
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/10.jpg  With size590848
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/11.jpg  With size5992704
succesfully loaded/home/tomna/NetBeansProjects/main/src/main/cars/12.jpg  With size5992704
Mat [ 1*71912448*CV_32FC1, isCont=true, isSubmat=false, nativeObj=0x7f5a38702220, dataAddr=0x7f595ddbc020 ]
edit retag flag offensive close merge delete

Comments

1

I don't think you're supposed to use the images themselves as your training matrix. You're supposed to distill them down to a set of features and use those. If your dimensionality is too high, the process is worthless.

Tetragramm gravatar imageTetragramm ( 2017-02-06 18:35:48 -0600 )edit

I agree Tetragramm. If you want to use whole images for training, it's better to use a neural network (ml::ANN) than a SVM.

kbarni gravatar imagekbarni ( 2017-02-07 03:21:57 -0600 )edit