001// 002// This file is auto-generated. Please don't modify it! 003// 004package org.opencv.ml; 005 006import org.opencv.core.Algorithm; 007import org.opencv.core.Mat; 008import org.opencv.ml.TrainData; 009 010// C++: class StatModel 011/** 012 * Base class for statistical models in OpenCV ML. 013 */ 014public class StatModel extends Algorithm { 015 016 protected StatModel(long addr) { super(addr); } 017 018 // internal usage only 019 public static StatModel __fromPtr__(long addr) { return new StatModel(addr); } 020 021 // C++: enum Flags (cv.ml.StatModel.Flags) 022 public static final int 023 UPDATE_MODEL = 1, 024 RAW_OUTPUT = 1, 025 COMPRESSED_INPUT = 2, 026 PREPROCESSED_INPUT = 4; 027 028 029 // 030 // C++: int cv::ml::StatModel::getVarCount() 031 // 032 033 /** 034 * Returns the number of variables in training samples 035 * @return automatically generated 036 */ 037 public int getVarCount() { 038 return getVarCount_0(nativeObj); 039 } 040 041 042 // 043 // C++: bool cv::ml::StatModel::empty() 044 // 045 046 public boolean empty() { 047 return empty_0(nativeObj); 048 } 049 050 051 // 052 // C++: bool cv::ml::StatModel::isTrained() 053 // 054 055 /** 056 * Returns true if the model is trained 057 * @return automatically generated 058 */ 059 public boolean isTrained() { 060 return isTrained_0(nativeObj); 061 } 062 063 064 // 065 // C++: bool cv::ml::StatModel::isClassifier() 066 // 067 068 /** 069 * Returns true if the model is classifier 070 * @return automatically generated 071 */ 072 public boolean isClassifier() { 073 return isClassifier_0(nativeObj); 074 } 075 076 077 // 078 // C++: bool cv::ml::StatModel::train(Ptr_TrainData trainData, int flags = 0) 079 // 080 081 /** 082 * Trains the statistical model 083 * 084 * @param trainData training data that can be loaded from file using TrainData::loadFromCSV or 085 * created with TrainData::create. 086 * @param flags optional flags, depending on the model. Some of the models can be updated with the 087 * new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP). 088 * @return automatically generated 089 */ 090 public boolean train(TrainData trainData, int flags) { 091 return train_0(nativeObj, trainData.getNativeObjAddr(), flags); 092 } 093 094 /** 095 * Trains the statistical model 096 * 097 * @param trainData training data that can be loaded from file using TrainData::loadFromCSV or 098 * created with TrainData::create. 099 * new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP). 100 * @return automatically generated 101 */ 102 public boolean train(TrainData trainData) { 103 return train_1(nativeObj, trainData.getNativeObjAddr()); 104 } 105 106 107 // 108 // C++: bool cv::ml::StatModel::train(Mat samples, int layout, Mat responses) 109 // 110 111 /** 112 * Trains the statistical model 113 * 114 * @param samples training samples 115 * @param layout See ml::SampleTypes. 116 * @param responses vector of responses associated with the training samples. 117 * @return automatically generated 118 */ 119 public boolean train(Mat samples, int layout, Mat responses) { 120 return train_2(nativeObj, samples.nativeObj, layout, responses.nativeObj); 121 } 122 123 124 // 125 // C++: float cv::ml::StatModel::calcError(Ptr_TrainData data, bool test, Mat& resp) 126 // 127 128 /** 129 * Computes error on the training or test dataset 130 * 131 * @param data the training data 132 * @param test if true, the error is computed over the test subset of the data, otherwise it's 133 * computed over the training subset of the data. Please note that if you loaded a completely 134 * different dataset to evaluate already trained classifier, you will probably want not to set 135 * the test subset at all with TrainData::setTrainTestSplitRatio and specify test=false, so 136 * that the error is computed for the whole new set. Yes, this sounds a bit confusing. 137 * @param resp the optional output responses. 138 * 139 * The method uses StatModel::predict to compute the error. For regression models the error is 140 * computed as RMS, for classifiers - as a percent of missclassified samples (0%-100%). 141 * @return automatically generated 142 */ 143 public float calcError(TrainData data, boolean test, Mat resp) { 144 return calcError_0(nativeObj, data.getNativeObjAddr(), test, resp.nativeObj); 145 } 146 147 148 // 149 // C++: float cv::ml::StatModel::predict(Mat samples, Mat& results = Mat(), int flags = 0) 150 // 151 152 /** 153 * Predicts response(s) for the provided sample(s) 154 * 155 * @param samples The input samples, floating-point matrix 156 * @param results The optional output matrix of results. 157 * @param flags The optional flags, model-dependent. See cv::ml::StatModel::Flags. 158 * @return automatically generated 159 */ 160 public float predict(Mat samples, Mat results, int flags) { 161 return predict_0(nativeObj, samples.nativeObj, results.nativeObj, flags); 162 } 163 164 /** 165 * Predicts response(s) for the provided sample(s) 166 * 167 * @param samples The input samples, floating-point matrix 168 * @param results The optional output matrix of results. 169 * @return automatically generated 170 */ 171 public float predict(Mat samples, Mat results) { 172 return predict_1(nativeObj, samples.nativeObj, results.nativeObj); 173 } 174 175 /** 176 * Predicts response(s) for the provided sample(s) 177 * 178 * @param samples The input samples, floating-point matrix 179 * @return automatically generated 180 */ 181 public float predict(Mat samples) { 182 return predict_2(nativeObj, samples.nativeObj); 183 } 184 185 186 @Override 187 protected void finalize() throws Throwable { 188 delete(nativeObj); 189 } 190 191 192 193 // C++: int cv::ml::StatModel::getVarCount() 194 private static native int getVarCount_0(long nativeObj); 195 196 // C++: bool cv::ml::StatModel::empty() 197 private static native boolean empty_0(long nativeObj); 198 199 // C++: bool cv::ml::StatModel::isTrained() 200 private static native boolean isTrained_0(long nativeObj); 201 202 // C++: bool cv::ml::StatModel::isClassifier() 203 private static native boolean isClassifier_0(long nativeObj); 204 205 // C++: bool cv::ml::StatModel::train(Ptr_TrainData trainData, int flags = 0) 206 private static native boolean train_0(long nativeObj, long trainData_nativeObj, int flags); 207 private static native boolean train_1(long nativeObj, long trainData_nativeObj); 208 209 // C++: bool cv::ml::StatModel::train(Mat samples, int layout, Mat responses) 210 private static native boolean train_2(long nativeObj, long samples_nativeObj, int layout, long responses_nativeObj); 211 212 // C++: float cv::ml::StatModel::calcError(Ptr_TrainData data, bool test, Mat& resp) 213 private static native float calcError_0(long nativeObj, long data_nativeObj, boolean test, long resp_nativeObj); 214 215 // C++: float cv::ml::StatModel::predict(Mat samples, Mat& results = Mat(), int flags = 0) 216 private static native float predict_0(long nativeObj, long samples_nativeObj, long results_nativeObj, int flags); 217 private static native float predict_1(long nativeObj, long samples_nativeObj, long results_nativeObj); 218 private static native float predict_2(long nativeObj, long samples_nativeObj); 219 220 // native support for java finalize() 221 private static native void delete(long nativeObj); 222 223}