首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

LIRE的使用:搜寻相似的图片

2013-10-16 
LIRE的使用:搜索相似的图片使用?ImageSearcherFactory?创建?ImageSearcher。例如ImageSearcherFactory.crea

LIRE的使用:搜索相似的图片

使用?ImageSearcherFactory?创建?ImageSearcher。例如ImageSearcherFactory.createDefaultSearcher()

?ImageSearcher?可以通过?InputStream?或?BufferedImage,或者一个描述图像的Lucene的?Document?进行检索。 例如使用search(BufferedImage, IndexReader)?或者search(Document, IndexReader).

返回的结果是一个?ImageSearchHits?类似于Lucene 中的Hits。

/** * Simple image retrieval with Lire * @author Mathias Lux, mathias <at> juggle <dot> at */public class Searcher {    public static void main(String[] args) throws IOException {        // Checking if arg[0] is there and if it is an image.        BufferedImage img = null;        boolean passed = false;        if (args.length > 0) {            File f = new File(args[0]);            if (f.exists()) {                try {                    img = ImageIO.read(f);                    passed = true;                } catch (IOException e) {                    e.printStackTrace();                  }            }        }        if (!passed) {            System.out.println("No image given as first argument.");            System.out.println("Run "Searcher <query image>" to search for <query image>.");            System.exit(1);        }         IndexReader ir = DirectoryReader.open(FSDirectory.open(new File("index")));        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);        }    }}

热点排行