lire的程序應該是怎樣的?
我理解的是用一個圖片提取特征去得到索引,
根據這個索引去檢索一個圖片庫,找到類似的。
但我在網上得到的demo是這樣的:
boolean passed = false;
args = new String[]{"E:\\workspaces\\simpleapp\\images"}; //圖片存放目錄,自行更改
if (args.length > 0) {
File f = new File(args[0]);
System.out.println("Indexing images in " + args[0]);
if (f.exists() && f.isDirectory()) passed = true;
}
if (!passed) {
System.out.println("No directory given as first argument.");
System.out.println("Run \"Indexer <directory>\" to index files of a directory.");
System.exit(1);
}
// 獲取所有目錄下的圖片
ArrayList<String> images = FileUtils.getAllImages(new File(args[0]), true);
// 建立一個CEDD檔案生成器并且索引所有圖片
DocumentBuilder builder = DocumentBuilderFactory.getCEDDDocumentBuilder();
// 建立一個Lucene寫索引工具
IndexWriterConfig conf = new IndexWriterConfig(LuceneUtils.LUCENE_VERSION,
new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION));
IndexWriter iw = new IndexWriter(FSDirectory.open(new File("index")), conf);
// 回圈索引圖片
for (Iterator<String> it = images.iterator(); it.hasNext(); ) {
String imageFilePath = it.next();
System.out.println("Indexing " + imageFilePath);
try {
BufferedImage img = ImageIO.read(new FileInputStream(imageFilePath));
Document document = builder.createDocument(img, imageFilePath);
iw.addDocument(document);
} catch (Exception e) {
System.err.println("Error reading image or indexing it.");
e.printStackTrace();
}
}
// 關閉寫索引工具
iw.close();
System.out.println("Finished indexing.");
為什么它是用去一群圖片去寫索引,不是應該用索引去檢索圖片嗎
uj5u.com熱心網友回復:
百度搜相關關鍵字。uj5u.com熱心網友回復:
就是搜了很久才來這里的轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/92531.html
標籤:圖形處理/算法
