Esempio n. 1
0
  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();
  }
  private Field[] getLocalDescriptorFields(
      BufferedImage image, ExtractorItem extractorItem, LinkedList<Cluster[]> listOfCodebooks) {
    LocalFeatureExtractor localFeatureExtractor =
        extractLocalFeatures(image, (LocalFeatureExtractor) extractorItem.getExtractorInstance());

    return createLocalDescriptorFields(
        localFeatureExtractor.getFeatures(), extractorItem, listOfCodebooks);
  }
  public LocalFeatureExtractor extractLocalFeatures(
      BufferedImage image, LocalFeatureExtractor localFeatureExtractor) {
    assert (image != null);
    // Scaling image is especially with the correlogram features very important!
    // All images are scaled to guarantee a certain upper limit for indexing.
    if (Math.max(image.getHeight(), image.getWidth()) > DocumentBuilder.MAX_IMAGE_DIMENSION) {
      image = ImageUtils.scaleImage(image, DocumentBuilder.MAX_IMAGE_DIMENSION);
    }

    localFeatureExtractor.extract(image);
    return localFeatureExtractor;
  }