List of usage examples for org.apache.lucene.document StoredField StoredField
public StoredField(String name, double value)
From source file:net.semanticmetadata.lire.imageanalysis.OpponentHistogramTest.java
License:Open Source License
public void testFromString() { String q = "0-0-0-0-0-12-8-0-0-62-5a-0-0-0-0-0-0-0-0-0-0-48-8-0-0-29-2b-0-0-0-0-0-0-0-0-0-0-58-4-0-0-b-7f-0-0-0-0-0-0-0-0-0-0-16-b-0-0-2-72-0-0-0-0-0"; String[] tmp = q.split("-"); byte[] tmpByte = new byte[tmp.length]; for (int i = 0; i < tmp.length; i++) { tmpByte[i] = Byte.parseByte(tmp[i], 16); }/*from w w w. j a v a2s . c om*/ OpponentHistogram o = new OpponentHistogram(); o.setByteArrayRepresentation(tmpByte); Document d = new Document(); d.add(new StoredField("featOpHist", o.getByteArrayRepresentation())); d.add(new TextField("featOpHist" + "_hash", SerializationUtils.arrayToString(BitSampling.generateHashes(o.getDoubleHistogram())), Field.Store.YES)); }
From source file:net.semanticmetadata.lire.impl.docbuilder.GenericDocumentBuilder.java
License:Open Source License
public Field[] createDescriptorFields(BufferedImage image) { Field[] result;/*from www.j a va2 s . c om*/ if (hashingEnabled) result = new Field[2]; else result = new Field[1]; String featureString = ""; assert (image != null); BufferedImage bimg = image; // Scaling image is especially with the correlogram features very important! // All images are scaled to guarantee a certain upper limit for indexing. if (Math.max(image.getHeight(), image.getWidth()) > MAX_IMAGE_DIMENSION) { bimg = ImageUtils.scaleImage(image, MAX_IMAGE_DIMENSION); } Document doc = null; try { logger.finer("Starting extraction from image [" + descriptorClass.getName() + "]."); LireFeature lireFeature = null; lireFeature = descriptorClass.newInstance(); lireFeature.extract(bimg); // featureString = vd.getStringRepresentation(); logger.fine("Extraction finished [" + descriptorClass.getName() + "]."); // TODO: Stored field is compressed and upon search decompression takes a lot of time (> 50% with a small index with 50k images). Find something else ... result[0] = new StoredField(fieldName, lireFeature.getByteArrayRepresentation()); // if BitSampling is an issue we add a field with the given hashFunctionsFileName and the suffix "hash": if (hashingEnabled) { // TODO: check eventually if there is a more compressed string version of the integers. i.e. the hex string if (lireFeature.getDoubleHistogram().length <= 3100) { int[] hashes; if (hashingMode == HashingMode.BitSampling) { hashes = BitSampling.generateHashes(lireFeature.getDoubleHistogram()); } else { hashes = LocalitySensitiveHashing.generateHashes(lireFeature.getDoubleHistogram()); } result[1] = new TextField(fieldName + HASH_FIELD_SUFFIX, SerializationUtils.arrayToString(hashes), Field.Store.YES); } else System.err.println("Could not create hashes, feature vector too long: " + lireFeature.getDoubleHistogram().length + " (" + lireFeature.getClass().getName() + ")"); } } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return result; }
From source file:net.semanticmetadata.lire.impl.docbuilder.MSERDocumentBuilder.java
License:Open Source License
public Document createDocument(BufferedImage image, ImageInfo imageInfo) { Document doc = null;/* w w w . j a v a 2 s . c om*/ try { // convert to grey ... BufferedImage image1 = convertImageToGrey(image); // extract features from image: List<MSERFeature> features = extractor.computeMSERFeatures(image1); ImageUtils.invertImage(image1); // invert grey features.addAll(extractor.computeMSERFeatures(image1)); // create new document: doc = new Document(); if (features.size() < 1) { System.err.println("No MSER features found for " + imageInfo.getTitle()); // } else { // System.out.println("features.size() = " + features.size()); } for (Iterator<MSERFeature> fit = features.iterator(); fit.hasNext();) { MSERFeature f = fit.next(); boolean skip = false; // add each feature to the document: // check first if NaN!! for (int j = 0; j < f.descriptor.length; j++) { if (Double.isNaN(f.descriptor[j])) skip = true; break; } if (!skip) doc.add(new StoredField(DocumentBuilder.FIELD_NAME_MSER, f.getByteArrayRepresentation())); else { // System.err.println("Found NaN in features in file " + identifier + ". "); } } } catch (Exception e) { e.printStackTrace(); } DocumentUtils.appendImageInfoFields(doc, imageInfo); return doc; }
From source file:net.semanticmetadata.lire.impl.docbuilder.SiftDocumentBuilder.java
License:Open Source License
@Override public Field[] createDescriptorFields(BufferedImage image) { Field[] result = null;/* w ww .j a v a2s.c o m*/ try { // extract features from image: List<Feature> features = extractor.computeSiftFeatures(image); result = new Field[features.size()]; int count = 0; // create new document: for (Iterator<Feature> fit = features.iterator(); fit.hasNext();) { Feature f = fit.next(); result[count] = new StoredField(DocumentBuilder.FIELD_NAME_SIFT, f.getByteArrayRepresentation()); count++; } } catch (IOException e) { logger.severe(e.getMessage()); } return result; }
From source file:net.semanticmetadata.lire.impl.docbuilder.SiftDocumentBuilder.java
License:Open Source License
public Document createDocument(BufferedImage image, ImageInfo imageInfo) { Document doc = null;//w ww . ja v a 2 s .c o m try { // extract features from image: List<Feature> features = extractor.computeSiftFeatures(image); // create new document: doc = new Document(); for (Iterator<Feature> fit = features.iterator(); fit.hasNext();) { Feature f = fit.next(); // add each feature to the document: doc.add(new StoredField(DocumentBuilder.FIELD_NAME_SIFT, f.getByteArrayRepresentation())); } } catch (IOException e) { logger.severe(e.getMessage()); } DocumentUtils.appendImageInfoFields(doc, imageInfo); return doc; }
From source file:net.semanticmetadata.lire.impl.docbuilder.SurfDocumentBuilder.java
License:Open Source License
@Override public Field[] createDescriptorFields(BufferedImage image) { Field[] result = null;/*from w ww .j av a 2 s. c o m*/ Surf s = new Surf(image); List<SURFInterestPoint> interestPoints = s.getFreeOrientedInterestPoints(); result = new Field[interestPoints.size()]; int count = 0; for (Iterator<SURFInterestPoint> sipi = interestPoints.iterator(); sipi.hasNext();) { SURFInterestPoint sip = sipi.next(); SurfFeature sf = new SurfFeature(sip); result[count] = (new StoredField(DocumentBuilder.FIELD_NAME_SURF, sf.getByteArrayRepresentation())); count++; } return result; }
From source file:net.semanticmetadata.lire.impl.docbuilder.SurfDocumentBuilder.java
License:Open Source License
public Document createDocument(BufferedImage image, ImageInfo imageInfo) { Document doc = null;//from w ww . ja va 2s . c o m Surf s = new Surf(image); List<SURFInterestPoint> interestPoints = s.getFreeOrientedInterestPoints(); doc = new Document(); for (Iterator<SURFInterestPoint> sipi = interestPoints.iterator(); sipi.hasNext();) { SURFInterestPoint sip = sipi.next(); SurfFeature sf = new SurfFeature(sip); doc.add(new StoredField(DocumentBuilder.FIELD_NAME_SURF, sf.getByteArrayRepresentation())); } DocumentUtils.appendImageInfoFields(doc, imageInfo); return doc; }
From source file:net.semanticmetadata.lire.impl.GenericDocumentBuilder.java
License:Open Source License
public Field[] createDescriptorFields(BufferedImage image) { Field[] result;/*from www. ja va2s .com*/ if (hashingEnabled) result = new Field[2]; else result = new Field[1]; String featureString = ""; assert (image != null); BufferedImage bimg = image; // Scaling image is especially with the correlogram features very important! // All images are scaled to guarantee a certain upper limit for indexing. if (Math.max(image.getHeight(), image.getWidth()) > MAX_IMAGE_DIMENSION) { bimg = ImageUtils.scaleImage(image, MAX_IMAGE_DIMENSION); } Document doc = null; try { logger.finer("Starting extraction from image [" + descriptorClass.getName() + "]."); LireFeature lireFeature = null; lireFeature = descriptorClass.newInstance(); lireFeature.extract(bimg); // featureString = vd.getStringRepresentation(); logger.fine("Extraction finished [" + descriptorClass.getName() + "]."); // TODO: Stored field is compressed and upon search decompression takes a lot of time (> 50% with a small index with 50k images). Find something else ... result[0] = new StoredField(fieldName, new BytesRef(lireFeature.getByteArrayRepresentation())); // if BitSampling is an issue we add a field with the given hashFunctionsFileName and the suffix "hash": if (hashingEnabled) { // TODO: check eventually if there is a more compressed string version of the integers. i.e. the hex string if (lireFeature.getDoubleHistogram().length <= 3100) { int[] hashes; if (hashingMode == HashingMode.BitSampling) { hashes = BitSampling.generateHashes(lireFeature.getDoubleHistogram()); } else { hashes = LocalitySensitiveHashing.generateHashes(lireFeature.getDoubleHistogram()); } result[1] = new TextField(fieldName + HASH_FIELD_SUFFIX, SerializationUtils.arrayToString(hashes), Field.Store.YES); } else System.err.println("Could not create hashes, feature vector too long: " + lireFeature.getDoubleHistogram().length + " (" + lireFeature.getClass().getName() + ")"); } } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return result; }
From source file:net.semanticmetadata.lire.impl.MSERDocumentBuilder.java
License:Open Source License
public Document createDocument(BufferedImage image, String identifier) { Document doc = null;//from w w w .j a v a 2 s. co m try { // convert to grey ... BufferedImage image1 = convertImageToGrey(image); // extract features from image: List<MSERFeature> features = extractor.computeMSERFeatures(image1); ImageUtils.invertImage(image1); // invert grey features.addAll(extractor.computeMSERFeatures(image1)); // create new document: doc = new Document(); if (features.size() < 1) { System.err.println("No MSER features found for " + identifier); // } else { // System.out.println("features.size() = " + features.size()); } for (Iterator<MSERFeature> fit = features.iterator(); fit.hasNext();) { MSERFeature f = fit.next(); boolean skip = false; // add each feature to the document: // check first if NaN!! for (int j = 0; j < f.getDoubleHistogram().length; j++) { if (Double.isNaN(f.getDoubleHistogram()[j])) skip = true; break; } if (!skip) doc.add(new StoredField(DocumentBuilder.FIELD_NAME_MSER, f.getByteArrayRepresentation())); else { // System.err.println("Found NaN in features in file " + identifier + ". "); } } if (identifier != null) { doc.add(new StringField(DocumentBuilder.FIELD_NAME_IDENTIFIER, identifier, Field.Store.YES)); } } catch (Exception e) { e.printStackTrace(); } return doc; }
From source file:net.semanticmetadata.lire.impl.SiftDocumentBuilder.java
License:Open Source License
public Document createDocument(BufferedImage image, String identifier) { Document doc = null;/*w w w.j a v a2 s .c o m*/ try { // extract features from image: List<Feature> features = extractor.computeSiftFeatures(image); // create new document: doc = new Document(); for (Iterator<Feature> fit = features.iterator(); fit.hasNext();) { Feature f = fit.next(); // add each feature to the document: doc.add(new StoredField(DocumentBuilder.FIELD_NAME_SIFT, f.getByteArrayRepresentation())); } if (identifier != null) doc.add(new StringField(DocumentBuilder.FIELD_NAME_IDENTIFIER, identifier, Field.Store.YES)); } catch (IOException e) { logger.severe(e.getMessage()); } return doc; }