本文整理匯總了Java中org.opencv.ml.KNearest類的典型用法代碼示例。如果您正苦於以下問題:Java KNearest類的具體用法?Java KNearest怎麽用?Java KNearest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
KNearest類屬於org.opencv.ml包,在下文中一共展示了KNearest類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createClassifier
import org.opencv.ml.KNearest; //導入依賴的package包/類
@Override
protected KNearest createClassifier() {
KNearest classifier = KNearest.create();
// System.out.println("Default K: " + classifier.getDefaultK());
ParameterList params = getParameterList();
if (params != null) {
classifier.setIsClassifier(true);
classifier.setDefaultK(params.getIntParameterValue("k"));
}
return classifier;
}
示例2: loadFromFile
import org.opencv.ml.KNearest; //導入依賴的package包/類
@Override
public void loadFromFile() {
MatName mtrainingList = new MatName("TrainingList", trainingList);
List<MatName> listMat = new ArrayList<MatName>();
listMat.add(mtrainingList);
labelList = fh.loadIntegerList(fh.createLabelFile(fh.KNN_PATH, "train"));
labelMap = fh.getLabelMapFromFile(fh.KNN_PATH);
trainingList = fh.getMatListFromXml(listMat, fh.KNN_PATH, trainingFile).get(0).getMat();
labels = new Mat(labelList.size(), 1, CvType.CV_8UC1);
for (int i=0; i<labelList.size(); i++) {
Integer label = labelList.get(i);
// Fill shorter labels with 0s
labels.put(i, 0, label);
}
labels.convertTo(labels, CvType.CV_32F);
PreferencesHelper preferencesHelper = new PreferencesHelper(context);
k = preferencesHelper.getK();
knn = KNearest.create();
knn.setIsClassifier(true);
knn.train(trainingList, 0,labels);
}
開發者ID:Qualeams,項目名稱:Android-Face-Recognition-with-Deep-Learning-Library,代碼行數:28,代碼來源:KNearestNeighbor.java