本文整理汇总了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