public void testLocalExtract(ArrayList<String> images) throws IOException, IllegalAccessException, InstantiationException { LocalFeatureExtractor localFeatureExtractor = localFeatureClass.newInstance(); LocalDocumentBuilder localDocumentBuilder = new LocalDocumentBuilder(); AbstractAggregator aggregator = aggregatorClass.newInstance(); Cluster[] codebook32 = Cluster.readClusters(codebookPath + "CvSURF32"); Cluster[] codebook128 = Cluster.readClusters(codebookPath + "CvSURF128"); BufferedImage image; double[] featureVector; long ms, totalTime = 0; for (String path : images) { image = ImageIO.read(new FileInputStream(path)); ms = System.currentTimeMillis(); localDocumentBuilder.extractLocalFeatures(image, localFeatureExtractor); aggregator.createVectorRepresentation(localFeatureExtractor.getFeatures(), codebook32); ms = System.currentTimeMillis() - ms; totalTime += ms; featureVector = aggregator.getVectorRepresentation(); System.out.println( String.format("%.2f", (double) ms) + " ms. ~ " + path.substring(path.lastIndexOf('\\') + 1) + " ~ " + Arrays.toString(featureVector)); } System.out.println( localFeatureExtractor.getClassOfFeatures().newInstance().getFeatureName() + " " + String.format("%.2f", totalTime / (double) images.size()) + " ms each."); System.out.println(); }
public Field[] createLocalDescriptorFields( List<? extends LocalFeature> listOfLocalFeatures, ExtractorItem extractorItem, LinkedList<Cluster[]> listOfCodebooks) { Field[] result = new Field[listOfCodebooks.size() * 2]; int count = 0; for (Cluster[] codebook : listOfCodebooks) { aggregator.createVectorRepresentation(listOfLocalFeatures, codebook); result[count] = new StoredField( fieldNamesDictionary.get(extractorItem).get(codebook.length)[0], aggregator.getByteVectorRepresentation()); result[count + 1] = new TextField( fieldNamesDictionary.get(extractorItem).get(codebook.length)[1], aggregator.getStringVectorRepresentation(), Field.Store.YES); count += 2; } return result; }