LIRE代码剖析2——Index和Search代码解析
来源:互联网 发布:刘美麟因为爱情网络 编辑:程序博客网 时间:2024/06/14 00:14
上面使用的Index和Search两个类都做了什么呢?下面我们来分别解释。
众所周知,图像本身的信息是非常大的,因此直接检索计算量太大,基于内容的图像检索本质上是用一些特征来代表图像,这些特征往往是大小有限的字符数组,因此可以使用文本检索技术来检索。Index的过程就是先提取图像的特征,将其视为文本,然后使用lucene来检索的。
创建索引的过程:
File f = new File(fileDesDir);//文件目录
// 打开文件目录,读取所有图像
ArrayList<String> images =FileUtils.getAllImages(new File(fileDesDir),true);
//创建一个 CEDD文档 builder ,然后对所有的文件创建CEDD索引.
DocumentBuilder builder =DocumentBuilderFactory.getCEDDDocumentBuilder();
// 创建一个 Lucene IndexWriter
IndexWriterConfig conf = newIndexWriterConfig(Version.LUCENE_40,
new WhitespaceAnalyzer(Version.LUCENE_40));
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(newFileInputStream(imageFilePath));
Document document = builder.createDocument(img,imageFilePath);
iw.addDocument(document);
} catch (Exception e) {
System.err.println("Error reading image or indexing it.");
e.printStackTrace();
}
}
搜索的时候:
//index是在本地创建的索引文件夹
IndexReader ir = DirectoryReader.open(FSDirectory.open(new File("index")));
//创建CEDD图像实例
ImageSearcher searcher =ImageSearcherFactory.createCEDDImageSearcher(10);
//创建搜索匹配度列表
ImageSearchHits hits =searcher.search(img, ir);
for (int i = 0; i < hits.length(); i++) {
String fileName =hits.doc(i).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0];
System.out.println(hits.score(i) +": \t" +fileName);
}
- LIRE代码剖析2——Index和Search代码解析
- LIRE代码剖析4——LIRE中比较重要的方法
- LIRE代码剖析1——运行第一个图像检索
- LIRE代码剖析3——常用的特征提取与匹配方法
- LIRE代码剖析3——常用的特征提取与匹配方法
- LIRE原理与源码分析(一)——代码结构
- twemproxyRedis协议解析探索——剖析twemproxy代码正编
- twemproxyRedis协议解析探索——剖析twemproxy代码正编
- Discuz代码分析——index.php
- 建立index和search
- Lire源码解析一
- 连载:编写高效代码(2)——代码剖析,没有调查,就没有发言权
- 【代码积累-2】binary search
- 中国电信CDN规范解析INDEX文件的C代码实现
- JAVA基础2(代码剖析)
- 【leetcode】第74题 Search a 2D Matrix 题目+解析+JAVA代码
- Google custom search ——直接使用代码
- asterisk概述和代码解析
- TCP
- 招聘之面试流程总结_针对具有一定研发经历的求职者
- hdu 4240 Route Redundancy(最大流)
- 写给想当程序员的朋友
- 改进版截图函数(主要解决XP下保存对话框遮挡截图问题)
- LIRE代码剖析2——Index和Search代码解析
- poj2387
- VC++ 求绝对值函数
- theme508 邮件里面的订单列表信息修改
- eclipse 移植cocos2d-x工程 报错: Program "bash" is not found in PATH
- object 知识总结(案例学习)
- 我的思维导图
- poj2421
- Mysql中特殊字符的使用注意事项