Search in sources :

Example 1 with FeatureToWordHistogram_F64

use of boofcv.alg.scene.FeatureToWordHistogram_F64 in project BoofCV by lessthanoptimal.

the class ExampleClassifySceneKnn method loadAndCreateClassifier.

public void loadAndCreateClassifier() {
    // load results from a file
    List<HistogramScene> memory = UtilIO.load(HISTOGRAM_FILE_NAME);
    AssignCluster<double[]> assignment = UtilIO.load(CLUSTER_FILE_NAME);
    FeatureToWordHistogram_F64 featuresToHistogram = new FeatureToWordHistogram_F64(assignment, HISTOGRAM_HARD);
    // Provide the training results to K-NN and it will preprocess these results for quick lookup later on
    // Can use this classifier with saved results and avoid the
    classifier = new ClassifierKNearestNeighborsBow<>(nn, describeImage, featuresToHistogram);
    classifier.setClassificationData(memory, getScenes().size());
    classifier.setNumNeighbors(NUM_NEIGHBORS);
}
Also used : HistogramScene(boofcv.alg.scene.HistogramScene) FeatureToWordHistogram_F64(boofcv.alg.scene.FeatureToWordHistogram_F64)

Example 2 with FeatureToWordHistogram_F64

use of boofcv.alg.scene.FeatureToWordHistogram_F64 in project BoofCV by lessthanoptimal.

the class ExampleClassifySceneKnn method learnAndSave.

/**
 * Process all the data in the training data set to learn the classifications.  See code for details.
 */
public void learnAndSave() {
    System.out.println("======== Learning Classifier");
    // Either load pre-computed words or compute the words from the training images
    AssignCluster<double[]> assignment;
    if (new File(CLUSTER_FILE_NAME).exists()) {
        assignment = UtilIO.load(CLUSTER_FILE_NAME);
    } else {
        System.out.println(" Computing clusters");
        assignment = computeClusters();
    }
    // Use these clusters to assign features to words
    FeatureToWordHistogram_F64 featuresToHistogram = new FeatureToWordHistogram_F64(assignment, HISTOGRAM_HARD);
    // Storage for the work histogram in each image in the training set and their label
    List<HistogramScene> memory;
    if (!new File(HISTOGRAM_FILE_NAME).exists()) {
        System.out.println(" computing histograms");
        memory = computeHistograms(featuresToHistogram);
        UtilIO.save(memory, HISTOGRAM_FILE_NAME);
    }
}
Also used : HistogramScene(boofcv.alg.scene.HistogramScene) File(java.io.File) FeatureToWordHistogram_F64(boofcv.alg.scene.FeatureToWordHistogram_F64)

Aggregations

FeatureToWordHistogram_F64 (boofcv.alg.scene.FeatureToWordHistogram_F64)2 HistogramScene (boofcv.alg.scene.HistogramScene)2 File (java.io.File)1