Ask Your Question

Revision history [back]

opencv3.2 java svm.save(path) error

  public static final String SVM_MODEL_FILE_PATH = "C:\\Users\\tikkat3\\IdeaProjects\\VehicleLicenseOCR\\resources\\b_process\\svm/model";

void train(){
    //init SVM
    SVM svm = SVM.create();
    svm.setType(SVM.C_SVC);
    svm.setKernel(SVM.RBF);
    svm.setDegree(0.1);
    // 1.4 bug fix: old 1.4 ver gamma is 1
    svm.setGamma(0.1);
    svm.setCoef0(0.1);
    svm.setC(1);
    svm.setNu(0.1);
    svm.setP(0.1);
    svm.setTermCriteria(new TermCriteria(TermCriteria.EPS, 100, 1));

    System.out.println("load data...");
    //load train data
    TrainData trainData = loadTrainData();

    //train
    long star = System.currentTimeMillis();
    System.out.println("start train...");
    svm.train(trainData.getSamples(),Ml.ROW_SAMPLE,trainData.getResponses());//correct
    //svm.train(trainData); wrong
    System.out.println("end train...total time : " +(System.currentTimeMillis()-star) + "ms");

    //save svm.xml
    svm.save(SVM_MODEL_FILE_PATH);
    System.out.println("save the train model...");

}

svm.save(SVM_MODEL_FILE_PATH); error:

Exception in thread "main" java.lang.Exception: unknown exception at org.opencv.core.Algorithm.save_0(Native Method) at org.opencv.core.Algorithm.save(Algorithm.java:53) at svm.SvmTrain.train(SvmTrain.java:62) at svm.SvmTrain.main(SvmTrain.java:31)