Search in sources :

Example 1 with ConfigDenseSurfFast

use of boofcv.factory.feature.dense.ConfigDenseSurfFast in project BoofCV by lessthanoptimal.

the class ExampleClassifySceneKnn method main.

public static void main(String[] args) {
    var surfFast = new ConfigDenseSurfFast(new DenseSampling(8, 8));
    // ConfigDenseSurfStable surfStable = new ConfigDenseSurfStable(new DenseSampling(8,8));
    // ConfigDenseSift sift = new ConfigDenseSift(new DenseSampling(6,6));
    // ConfigDenseHoG hog = new ConfigDenseHoG();
    DescribeImageDense<GrayU8, TupleDesc_F64> desc = FactoryDescribeImageDense.surfFast(surfFast, GrayU8.class);
    // FactoryDescribeImageDense.surfStable(surfStable, GrayU8.class);
    // FactoryDescribeImageDense.sift(sift, GrayU8.class);
    // FactoryDescribeImageDense.hog(hog, ImageType.single(GrayU8.class));
    var configKMeans = new ConfigKMeans();
    configKMeans.maxIterations = MAX_KNN_ITERATIONS;
    configKMeans.reseedAfterIterations = 20;
    ComputeClusters<double[]> clusterer = FactoryClustering.kMeans_MT(configKMeans, desc.createDescription().size(), 200, double[].class);
    clusterer.setVerbose(true);
    // The _MT tells it to use the threaded version. This can run MUCH faster.
    int pointDof = desc.createDescription().size();
    NearestNeighbor<HistogramScene> nn = FactoryNearestNeighbor.exhaustive(new KdTreeHistogramScene_F64(pointDof));
    ExampleClassifySceneKnn example = new ExampleClassifySceneKnn(desc, clusterer, nn);
    var trainingDir = new File(UtilIO.pathExample("learning/scene/train"));
    var testingDir = new File(UtilIO.pathExample("learning/scene/test"));
    if (!trainingDir.exists() || !testingDir.exists()) {
        String addressSrc = "http://boofcv.org/notwiki/largefiles/bow_data_v001.zip";
        File dst = new File(trainingDir.getParentFile(), "bow_data_v001.zip");
        try {
            DeepBoofDataBaseOps.download(addressSrc, dst);
            DeepBoofDataBaseOps.decompressZip(dst, dst.getParentFile(), true);
            System.out.println("Download complete!");
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    } else {
        System.out.println("Delete and download again if there are file not found errors");
        System.out.println("   " + trainingDir);
        System.out.println("   " + testingDir);
    }
    example.loadSets(trainingDir, null, testingDir);
    // train the classifier
    example.learnAndSave();
    // now load it for evaluation purposes from the files
    example.loadAndCreateClassifier();
    // test the classifier on the test set
    Confusion confusion = example.evaluateTest();
    confusion.getMatrix().print();
    System.out.println("Accuracy = " + confusion.computeAccuracy());
    // Show confusion matrix
    // Not the best coloration scheme... perfect = red diagonal and blue elsewhere.
    ShowImages.showWindow(new ConfusionMatrixPanel(confusion.getMatrix(), example.getScenes(), 400, true), "Confusion Matrix", true);
// For SIFT descriptor the accuracy is          54.0%
// For  "fast"  SURF descriptor the accuracy is 52.2%
// For "stable" SURF descriptor the accuracy is 49.4%
// For HOG                                      53.3%
// SURF results are interesting. "Stable" is significantly better than "fast"!
// One explanation is that the descriptor for "fast" samples a smaller region than "stable", by a
// couple of pixels at scale of 1. Thus there is less overlap between the features.
// Reducing the size of "stable" to 0.95 does slightly improve performance to 50.5%, can't scale it down
// much more without performance going down
}
Also used : ConfusionMatrixPanel(boofcv.gui.learning.ConfusionMatrixPanel) TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) KdTreeHistogramScene_F64(boofcv.alg.scene.KdTreeHistogramScene_F64) DenseSampling(boofcv.factory.feature.dense.DenseSampling) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Confusion(boofcv.struct.learning.Confusion) ConfigDenseSurfFast(boofcv.factory.feature.dense.ConfigDenseSurfFast) HistogramScene(boofcv.alg.scene.HistogramScene) GrayU8(boofcv.struct.image.GrayU8) ConfigKMeans(org.ddogleg.clustering.ConfigKMeans) File(java.io.File)

Aggregations

HistogramScene (boofcv.alg.scene.HistogramScene)1 KdTreeHistogramScene_F64 (boofcv.alg.scene.KdTreeHistogramScene_F64)1 ConfigDenseSurfFast (boofcv.factory.feature.dense.ConfigDenseSurfFast)1 DenseSampling (boofcv.factory.feature.dense.DenseSampling)1 ConfusionMatrixPanel (boofcv.gui.learning.ConfusionMatrixPanel)1 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)1 GrayU8 (boofcv.struct.image.GrayU8)1 Confusion (boofcv.struct.learning.Confusion)1 File (java.io.File)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ConfigKMeans (org.ddogleg.clustering.ConfigKMeans)1