zoukankan      html  css  js  c++  java
  • 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) + ": 	" + fileName);
            }
        }
    }


  • 相关阅读:
    FFT学习笔记
    FWT(Fast Walsh Transformation)快速沃尔什变换学习笔记
    GMS2游戏开发学习历程
    [BZOJ3238][AHOI2013]差异 [后缀数组+单调栈]
    Trie树简单讲解
    自己的题
    小技巧
    编程注意事项
    构造方法
    递归
  • 原文地址:https://www.cnblogs.com/leixiaohua1020/p/3902211.html
Copyright © 2011-2022 走看看