private void indexFiles(ArrayList<String> images, DocumentBuilder builder, String indexPath) throws IOException { // eventually check if the directory is there or not ... IndexWriter iw = LuceneUtils.createIndexWriter(testIndex, false); int count = 0; long time = System.currentTimeMillis(); for (String identifier : images) { // TODO: cut toes from the image ... -> doesn't work out very well. Stable at first, // decreasing then. // TODO: Joint Histogram ... // TODO: LSA / PCA on the vectors ...-> this looks like a job for me :-D // TODO: local features ... Document doc = null; if (cutImages) { BufferedImage bimg = ImageUtils.cropImage(ImageIO.read(new FileInputStream(identifier)), 0, 0, 200, 69); doc = builder.createDocument(bimg, identifier); } else doc = builder.createDocument(new FileInputStream(identifier), identifier); iw.addDocument(doc); count++; if (count % 100 == 0) { int percent = (int) Math.floor(((double) count * 100.0) / (double) images.size()); double timeTemp = (double) (System.currentTimeMillis() - time) / 1000d; int secsLeft = (int) Math.round(((timeTemp / (double) count) * (double) images.size()) - timeTemp); System.out.println(percent + "% finished (" + count + " files), " + secsLeft + " s left"); } } long timeTaken = (System.currentTimeMillis() - time); float sec = ((float) timeTaken) / 1000f; System.out.println(sec + " seconds taken, " + (timeTaken / count) + " ms per image."); iw.commit(); iw.close(); }
private Document indexFiles() throws IOException { System.out.println("---< indexing >-------------------------"); int count = 0; DocumentBuilder builder = getDocumentBuilder(); ArrayList<String> allImages = FileUtils.getAllImages(new File("wang-1000"), true); IndexWriter iw = LuceneUtils.createIndexWriter(indexPath, true); Document document = null; for (Iterator<String> iterator = allImages.iterator(); iterator.hasNext(); ) { String filename = iterator.next(); BufferedImage image = ImageIO.read(new FileInputStream(filename)); document = builder.createDocument(image, filename); iw.addDocument(document); count++; if (count % 50 == 0) System.out.println("finished " + (count * 100) / allImages.size() + "% of the images."); } iw.close(); return document; }
private void indexFiles(ArrayList<String> images, DocumentBuilder builder, String indexPath) throws IOException { // System.out.println(">> Indexing " + images.size() + " files."); // DocumentBuilder builder = DocumentBuilderFactory.getExtensiveDocumentBuilder(); // DocumentBuilder builder = DocumentBuilderFactory.getFastDocumentBuilder(); IndexWriter iw = LuceneUtils.createIndexWriter(indexPath, true); int count = 0; long time = System.currentTimeMillis(); for (String identifier : images) { Document doc = builder.createDocument(new FileInputStream(identifier), identifier); iw.addDocument(doc); count++; if (count % 100 == 0) System.out.println(count + " files indexed."); // if (count == 200) break; } long timeTaken = (System.currentTimeMillis() - time); float sec = ((float) timeTaken) / 1000f; System.out.println(sec + " seconds taken, " + (timeTaken / count) + " ms per image."); iw.commit(); iw.close(); }
/** * Index for each builder type * * @param image * @param picture_id * @param prefix * @param builder * @param conf * @throws IOException */ private static void luceneIndexer( BufferedImage image, UUID picture_id, String prefix, DocumentBuilder builder, IndexWriterConfig conf) throws IOException { File path = getPath(prefix); log.debug("creating indexed path " + path.getAbsolutePath()); IndexWriter iw = new IndexWriter(FSDirectory.open(path), conf); try { Document document = builder.createDocument(image, picture_id.toString()); iw.addDocument(document); } catch (Exception e) { System.err.println("Error reading image or indexing it."); e.printStackTrace(); } // closing the IndexWriter iw.close(); }