Example #1
0
 private DocumentBuilder getDocumentBuilder() {
   ChainedDocumentBuilder builder = new ChainedDocumentBuilder();
   builder.addBuilder(DocumentBuilderFactory.getCEDDDocumentBuilder());
   builder.addBuilder(DocumentBuilderFactory.getAutoColorCorrelogramDocumentBuilder());
   builder.addBuilder(DocumentBuilderFactory.getColorLayoutBuilder());
   return builder;
 }
Example #2
0
  protected void setUp() {
    builder = new ChainedDocumentBuilder();
    //        builder.addBuilder(new GenericDocumentBuilder(FuzzyColorHistogram.class,
    // "FIELD_FUZZYCOLORHIST"));
    //        builder.addBuilder(new GenericDocumentBuilder(JpegCoefficientHistogram.class,
    // "FIELD_JPEGCOEFFHIST"));
    //        builder.addBuilder(new GenericDocumentBuilder(HSVColorHistogram.class,
    // "FIELD_HSVCOLORHIST"));
    //        builder.addBuilder(new GenericDocumentBuilder(GeneralColorLayout.class,
    // "FIELD_GENCL"));
    //        builder.addBuilder(DocumentBuilderFactory.getColorHistogramDocumentBuilder());
    //        builder.addBuilder(DocumentBuilderFactory.getCEDDDocumentBuilder());
    //        builder.addBuilder(DocumentBuilderFactory.getFCTHDocumentBuilder());
    //        builder.addBuilder(new GenericDocumentBuilder(SimpleColorHistogram.class,
    // "FIELD_CH"));
    //        builder.addBuilder(new GenericDocumentBuilder(AutoColorCorrelogram.class,
    // "FIELD_ACC"));
    builder.addBuilder(DocumentBuilderFactory.getColorLayoutBuilder());
    builder.addBuilder(DocumentBuilderFactory.getEdgeHistogramBuilder());
    builder.addBuilder(DocumentBuilderFactory.getScalableColorBuilder());

    // creating test cases ...
    String testcasesDir = "C:\\Temp\\RGA\\cameraShots\\";
    testcases.put(testcasesDir + "bocajr.jpg", "sb_153.jpg");
    testcases.put(testcasesDir + "deskshot_01.jpg", "sb_196.jpg");
    testcases.put(testcasesDir + "deskshot_02.jpg", "sb_213.jpg");
    testcases.put(testcasesDir + "future.jpg", "sb_270.jpg");
    testcases.put(testcasesDir + "icecrystals.jpg", "sb_219.jpg");
    testcases.put(testcasesDir + "jedis.jpg", "sb_214.jpg");
    //        testcases.put(testcasesDir + "midnightfogs.jpg", "");
    //        testcases.put(testcasesDir + "myfile.jpg", "");
    //        testcases.put(testcasesDir + "new_01.jpg", "");
    testcases.put(testcasesDir + "stussey.jpg", "sb_136.jpg");
    testcases.put(testcasesDir + "supremelow.jpg", "sb_136.jpg");
    testcases.put(testcasesDir + "tiffany.jpg", "sb_130.jpg");
    //        testcases.put(testcasesDir + "unluckys.jpg", "");
  }
  public double testIndexing() throws IOException, IllegalAccessException, InstantiationException {
    LocalitySensitiveHashing.generateHashFunctions();
    LocalitySensitiveHashing.readHashFunctions();
    DocumentBuilder builder = new ChainedDocumentBuilder();
    ((ChainedDocumentBuilder) builder).addBuilder(DocumentBuilderFactory.getCEDDDocumentBuilder());

    //        System.out.println("-< Getting files to index >--------------");
    ArrayList<String> images = FileUtils.getAllImages(new File(testExtensive), true);
    //        System.out.println("-< Indexing " + images.size() + " files >--------------");

    IndexWriter iw =
        LuceneUtils.createIndexWriter(indexPath, true, LuceneUtils.AnalyzerType.WhitespaceAnalyzer);
    int count = 0;
    long time = System.currentTimeMillis();
    for (String identifier : images) {
      CEDD cedd = new CEDD();
      cedd.extract(ImageIO.read(new FileInputStream(identifier)));
      Document doc = new Document();
      doc.add(new Field(DocumentBuilder.FIELD_NAME_CEDD, cedd.getByteArrayRepresentation()));
      doc.add(
          new Field(
              DocumentBuilder.FIELD_NAME_IDENTIFIER,
              identifier,
              Field.Store.YES,
              Field.Index.NOT_ANALYZED));
      int[] hashes = LocalitySensitiveHashing.generateHashes(cedd.getDoubleHistogram());
      StringBuilder hash = new StringBuilder(512);
      for (int i = 0; i < hashes.length; i++) {
        hash.append(hashes[i]);
        hash.append(' ');
      }
      //            System.out.println("hash = " + hash);
      doc.add(new Field("hash", hash.toString(), Field.Store.YES, Field.Index.ANALYZED));
      iw.addDocument(doc);
      count++;
      //            if (count % 100 == 0) System.out.println(count + " files indexed.");
    }
    long timeTaken = (System.currentTimeMillis() - time);
    float sec = ((float) timeTaken) / 1000f;

    //        System.out.println(sec + " seconds taken, " + (timeTaken / count) + " ms per image.");
    iw.close();

    return testSearch();
  }
  public void testSiftIndexing() throws IOException {
    ArrayList<String> images = FileUtils.getAllImages(new File(testExtensive), true);
    ChainedDocumentBuilder db = new ChainedDocumentBuilder();
    db.addBuilder(new SiftDocumentBuilder());
    db.addBuilder(DocumentBuilderFactory.getCEDDDocumentBuilder());
    IndexWriter iw = LuceneUtils.createIndexWriter("sift-idx", true);

    for (int i = 0; i < images.size(); i++) {
      //            int sampleQuery = sampleQueries[i];
      //            String s = testExtensive + "/" + sampleQuery + ".jpg";
      iw.addDocument(db.createDocument(new FileInputStream(images.get(i)), images.get(i)));
      if (i % 100 == 99) System.out.print(".");
      if (i % 1000 == 999) System.out.print(" ~ " + i + " files indexed\n");
      if (i > 1000) break;
    }
    System.out.println("");
    iw.close();
  }
  /**
   * Index a picture
   *
   * @param source
   * @param picture_id
   * @param conf
   * @throws IOException
   */
  public static void index(byte[] source, UUID picture_id, IndexWriterConfig conf)
      throws IOException {
    ByteArrayInputStream in = new ByteArrayInputStream(source);
    BufferedImage image = ImageIO.read(in);

    // Creating an Lucene IndexWriter
    log.debug("Is Lucene configured? " + (conf == null));
    if (conf == null) {
      conf =
          new IndexWriterConfig(
              LuceneUtils.LUCENE_VERSION, new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION));
      conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
    }

    luceneIndexer(
        image,
        picture_id,
        FeatureEnumerate.AutoColorCorrelogram.getText(),
        DocumentBuilderFactory.getAutoColorCorrelogramDocumentBuilder(),
        conf);
    luceneIndexer(
        image,
        picture_id,
        FeatureEnumerate.CEDD.getText(),
        DocumentBuilderFactory.getCEDDDocumentBuilder(),
        conf);
    luceneIndexer(
        image,
        picture_id,
        FeatureEnumerate.ColorLayout.getText(),
        DocumentBuilderFactory.getColorLayoutBuilder(),
        conf);
    luceneIndexer(
        image,
        picture_id,
        FeatureEnumerate.EdgeHistogram.getText(),
        DocumentBuilderFactory.getEdgeHistogramBuilder(),
        conf);
    luceneIndexer(
        image,
        picture_id,
        FeatureEnumerate.ColorHistogram.getText(),
        DocumentBuilderFactory.getColorHistogramDocumentBuilder(),
        conf);
    luceneIndexer(
        image,
        picture_id,
        FeatureEnumerate.PHOG.getText(),
        DocumentBuilderFactory.getPHOGDocumentBuilder(),
        conf);
  }