use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class ExampleClassifySceneKnn method main.
public static void main(String[] args) {
ConfigDenseSurfFast 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 = (DescribeImageDense) FactoryDescribeImageDense.surfFast(surfFast, GrayU8.class);
// FactoryDescribeImageDense.surfStable(surfStable, GrayU8.class);
// FactoryDescribeImageDense.sift(sift, GrayU8.class);
// FactoryDescribeImageDense.hog(hog, ImageType.single(GrayU8.class));
ComputeClusters<double[]> clusterer = FactoryClustering.kMeans_F64(null, MAX_KNN_ITERATIONS, 20, 1e-6);
clusterer.setVerbose(true);
NearestNeighbor<HistogramScene> nn = FactoryNearestNeighbor.exhaustive();
ExampleClassifySceneKnn example = new ExampleClassifySceneKnn(desc, clusterer, nn);
File trainingDir = new File(UtilIO.pathExample("learning/scene/train"));
File 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 RuntimeException(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
}
use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class ExampleColorHistogramLookup method independentHueSat.
/**
* Computes two independent 1D histograms from hue and saturation. Less affects by sparsity, but can produce
* worse results since the basic assumption that hue and saturation are decoupled is most of the time false.
*/
public static List<double[]> independentHueSat(List<File> images) {
List<double[]> points = new ArrayList<>();
// The number of bins is an important parameter. Try adjusting it
TupleDesc_F64 histogramHue = new TupleDesc_F64(30);
TupleDesc_F64 histogramValue = new TupleDesc_F64(30);
List<TupleDesc_F64> histogramList = new ArrayList<>();
histogramList.add(histogramHue);
histogramList.add(histogramValue);
Planar<GrayF32> rgb = new Planar<>(GrayF32.class, 1, 1, 3);
Planar<GrayF32> hsv = new Planar<>(GrayF32.class, 1, 1, 3);
for (File f : images) {
BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
if (buffered == null)
throw new RuntimeException("Can't load image!");
rgb.reshape(buffered.getWidth(), buffered.getHeight());
hsv.reshape(buffered.getWidth(), buffered.getHeight());
ConvertBufferedImage.convertFrom(buffered, rgb, true);
ColorHsv.rgbToHsv_F32(rgb, hsv);
GHistogramFeatureOps.histogram(hsv.getBand(0), 0, 2 * Math.PI, histogramHue);
GHistogramFeatureOps.histogram(hsv.getBand(1), 0, 1, histogramValue);
// need to combine them into a single descriptor for processing later on
TupleDesc_F64 imageHist = UtilFeature.combine(histogramList, null);
// normalize so that image size doesn't matter
UtilFeature.normalizeL2(imageHist);
points.add(imageHist.value);
}
return points;
}
use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class TestDescribeRegionPointConvert method basic.
@Test
public void basic() {
DummyConvert convert = new DummyConvert();
DummyDescribe original = new DummyDescribe();
DescribeRegionPointConvert<GrayF32, TupleDesc_F64, TupleDesc_S8> alg = new DescribeRegionPointConvert<>(original, convert);
TupleDesc_S8 found = alg.createDescription();
assertTrue(found.value.length == 5);
assertFalse(original.calledImageSet);
alg.setImage(null);
assertTrue(original.calledImageSet);
alg.process(1, 2, 2, 2, found);
assertEquals(5, found.value[0]);
assertTrue(alg.requiresOrientation() == original.requiresOrientation());
assertTrue(alg.requiresRadius() == original.requiresRadius());
assertTrue(alg.getDescriptionType() == TupleDesc_S8.class);
}
use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class TestDescribeRegionPoint_SIFT method process.
@Test
public void process() {
GrayF32 image = new GrayF32(640, 480);
GImageMiscOps.fillUniform(image, rand, 0, 200);
DescribeRegionPoint_SIFT<GrayF32> alg = declare();
alg.setImage(image);
TupleDesc_F64 desc0 = alg.createDescription();
TupleDesc_F64 desc1 = alg.createDescription();
TupleDesc_F64 desc2 = alg.createDescription();
// same location, but different orientations and scales
assertTrue(alg.process(100, 120, 0.5, 10, desc0));
assertTrue(alg.process(100, 50, -1.1, 10, desc1));
assertTrue(alg.process(100, 50, 0.5, 7, desc2));
// should be 3 different descriptions
assertNotEquals(desc0.getDouble(0), desc1.getDouble(0), 1e-6);
assertNotEquals(desc0.getDouble(0), desc2.getDouble(0), 1e-6);
assertNotEquals(desc1.getDouble(0), desc2.getDouble(0), 1e-6);
// see if it blows up along the image border
assertTrue(alg.process(0, 120, 0.5, 10, desc0));
assertTrue(alg.process(100, 0, 0.5, 10, desc0));
assertTrue(alg.process(639, 120, 0.5, 10, desc0));
assertTrue(alg.process(100, 479, 0.5, 10, desc0));
}
use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class TestDescribeRegionPoint_SIFT method flags.
@Test
public void flags() {
DescribeRegionPoint_SIFT<GrayF32> alg = declare();
assertTrue(alg.requiresOrientation());
assertTrue(alg.requiresRadius());
TupleDesc_F64 desc = alg.createDescription();
assertEquals(128, desc.size());
assertEquals(2 * alg.describe.getCanonicalRadius(), alg.getCanonicalWidth(), 1e-8);
}
Aggregations