public static void main(String[] args) throws IOException { ArrayList<File> files = FileUtils.getAllImageFiles(new File("D:\\Temp\\tmp"), false); int count = 10; for (Iterator<File> iterator = files.iterator(); iterator.hasNext(); ) { File next = iterator.next(); BufferedImage img = ImageIO.read(next); BufferedImage toWrite = new BufferedImage(img.getWidth()*2, img.getHeight(), BufferedImage.TYPE_INT_RGB); toWrite.getGraphics().drawImage(img, 0, 0, null); BufferedImage bufferedImage = clusterPixels(img); toWrite.getGraphics().drawImage(bufferedImage, img.getWidth(), 0, null); ImageIO.write(toWrite, "png", new File("out_test_"+count+".png")); count++; } }
public void testSimple() throws IOException, IllegalAccessException, InstantiationException { ArrayList<String> images = FileUtils.readFileLines(new File(imagePath), true); testSimple(images); }
public static void zipDirectory(File directory, File base, ZipOutputStream zos) throws IOException { File[] files = directory.listFiles(); byte[] buffer = new byte[8192]; int read = 0; for (int i = 0, n = files.length; i < n; i++) { if (files[i].isDirectory()) { zipDirectory(files[i], base, zos); } else { FileInputStream in = new FileInputStream(files[i]); ZipEntry entry = new ZipEntry(files[i].getPath().substring(base.getPath().length() + 1)); zos.putNextEntry(entry); while (-1 != (read = in.read(buffer))) { zos.write(buffer, 0, read); } in.close(); } } }
public void testListFilesString() { // see if it just works. try { ArrayList<String> testdata1 = FileUtils.getAllImages(new File("testdata/ferrari/black"), true); assertEquals(19, testdata1.size()); } catch (IOException e) { e.printStackTrace(); } // see if it just fails. try { ArrayList<String> testdata2 = null; testdata2 = FileUtils.getAllImages(new File("testdata/ferrari/black/nothing"), true); fail(); } catch (Exception e) { // e.printStackTrace(); } }
@Override public void setUp() throws Exception { super.setUp(); // create infile. FileUtils.createImagefileList(new File(imageDirectory), infile, false); }
@Override public CharSequence getAdditionalFields(String filename) { StringBuilder sb = new StringBuilder(1024); int fileNumber = Integer.parseInt(filename.substring(filename.lastIndexOf("\\")).replaceAll("[^0-9]", "")) - 1; String tagFileName = "D:\\DataSets\\MirFlickr\\tags_raw\\" + (fileNumber/10000) + "\\" + fileNumber + ".txt"; // String tagFileName = filename.substring(0, filename.lastIndexOf("\\")) + "\\" + fileNumber + ".txt"; try { sb.append("<field name=\"tags\">"); StringBuilder tmp = new StringBuilder(); FileUtils.readWholeFile(new File(tagFileName), tmp); sb.append(tmp.toString().replaceAll("\\s", " ")); // replacing \n\r\t and all those with " " sb.append("</field>"); } catch (IOException e) { e.printStackTrace(); return ""; } return sb; } }
public void testIndexingSpeed() throws IOException { ArrayList<String> images = FileUtils.getAllImages(new File(testExtensive), false); testFeatureSpeed(images, AutoColorCorrelogram.class); testFeatureSpeed(images, CEDD.class); testFeatureSpeed(images, FCTH.class); testFeatureSpeed(images, JCD.class); testFeatureSpeed(images, SPACC.class); testFeatureSpeed(images, SPCEDD.class); testFeatureSpeed(images, SPFCTH.class); testFeatureSpeed(images, SPJCD.class); }
public static void main(String[] args) throws IOException { ArrayList<File> files = FileUtils.getAllImageFiles(new File("D:\\Temp\\tmp"), false); int count = 10; for (Iterator<File> iterator = files.iterator(); iterator.hasNext(); ) { File next = iterator.next(); BufferedImage img = ImageIO.read(next); BufferedImage toWrite = new BufferedImage(img.getWidth()*2, img.getHeight(), BufferedImage.TYPE_INT_RGB); toWrite.getGraphics().drawImage(img, 0, 0, null); BufferedImage bufferedImage = clusterPixels(img); toWrite.getGraphics().drawImage(bufferedImage, img.getWidth(), 0, null); ImageIO.write(toWrite, "png", new File("out_test_"+count+".png")); count++; } }
public void testLocalExtract() throws IOException, IllegalAccessException, InstantiationException { ArrayList<String> images = FileUtils.readFileLines(new File(imagePath), true); testLocalExtract(images); }
public static void zipDirectory(File directory, File base, ZipOutputStream zos) throws IOException { File[] files = directory.listFiles(); byte[] buffer = new byte[8192]; int read = 0; for (int i = 0, n = files.length; i < n; i++) { if (files[i].isDirectory()) { zipDirectory(files[i], base, zos); } else { FileInputStream in = new FileInputStream(files[i]); ZipEntry entry = new ZipEntry(files[i].getPath().substring(base.getPath().length() + 1)); zos.putNextEntry(entry); while (-1 != (read = in.read(buffer))) { zos.write(buffer, 0, read); } in.close(); } } }
/** * Returns all jpg images from a directory in an array. * * @param directory the directory to start with * @param descendIntoSubDirectories should we include sub directories? * @return an ArrayList<String> containing all the files or nul if none are found.. * @throws IOException */ public static ArrayList<String> getAllImages(File directory, boolean descendIntoSubDirectories) throws IOException { ArrayList<String> resultList = new ArrayList<String>(256); File[] f = directory.listFiles(); for (File file : f) { if (file != null && (file.getName().toLowerCase().endsWith(".jpg") || file.getName().toLowerCase().endsWith(".png") || file.getName().toLowerCase().endsWith(".gif")) && !file.getName().startsWith("tn_")) { resultList.add(file.getCanonicalPath()); } if (descendIntoSubDirectories && file.isDirectory()) { ArrayList<String> tmp = getAllImages(file, true); if (tmp != null) { resultList.addAll(tmp); } } } if (resultList.size() > 0) return resultList; else return null; }
public void testExtraction() throws IOException, IllegalAccessException, InstantiationException { ArrayList<File> imageFiles = FileUtils.getAllImageFiles(new File("src/test/resources/images"), true); GlobalFeature accid = gFeat.getClass().newInstance(); for (Iterator<File> iterator = imageFiles.iterator(); iterator.hasNext(); ) { File nextImage = iterator.next(); accid.extract(ImageIO.read(nextImage)); System.out.println(nextImage.getName() + ": " + Arrays.toString(accid.getFeatureVector())); } }
public void testLocal() throws IOException, IllegalAccessException, InstantiationException { ArrayList<String> images = FileUtils.readFileLines(new File(imagePath), true); testLocal(images); }
public static void zipDirectory(File directory, File base, ZipOutputStream zos) throws IOException { File[] files = directory.listFiles(); byte[] buffer = new byte[8192]; int read = 0; for (int i = 0, n = files.length; i < n; i++) { if (files[i].isDirectory()) { zipDirectory(files[i], base, zos); } else { FileInputStream in = new FileInputStream(files[i]); ZipEntry entry = new ZipEntry(files[i].getPath().substring(base.getPath().length() + 1)); zos.putNextEntry(entry); while (-1 != (read = in.read(buffer))) { zos.write(buffer, 0, read); } in.close(); } } }
writer = new IndexWriter(FSDirectory.open(new File(indexPath)), config); if (imageList == null) { files = FileUtils.getAllImages(new File(imageDirectory), true); } else { files = new LinkedList<String>();
public void testListFiles() { // see if it just works. try { ArrayList<File> testdata1 = FileUtils.getAllImageFiles(new File("testdata/ferrari/black"), true); assertEquals(19, testdata1.size()); } catch (IOException e) { e.printStackTrace(); } // see if it just fails. try { ArrayList<File> testdata2 = null; testdata2 = FileUtils.getAllImageFiles(new File("testdata/ferrari/black/nothing"), true); fail(); } catch (Exception e) { // e.printStackTrace(); } }
public void testGlobalExtract() throws IOException, IllegalAccessException, InstantiationException { ArrayList<String> images = FileUtils.readFileLines(new File(imagePath), true); testGlobalExtract(images); }
public void testDistance() throws IOException, IllegalAccessException, InstantiationException { ArrayList<File> imageFiles = FileUtils.getAllImageFiles(new File("src/test/resources/images"), true); LinkedList<GlobalFeature> features = new LinkedList<>(); for (Iterator<File> iterator = imageFiles.iterator(); iterator.hasNext(); ) { File nextImage = iterator.next(); GlobalFeature accid = gFeat.getClass().newInstance(); accid.extract(ImageIO.read(nextImage)); features.add(accid); assertEquals(accid.getDistance(accid), 0d); } }
public void testGlobal() throws IOException, IllegalAccessException, InstantiationException { ArrayList<String> images = FileUtils.readFileLines(new File(imagePath), true); testGlobal(images); }
public void testExtraction() throws IOException { ArrayList<File> imageFiles = FileUtils.getAllImageFiles(new File("src/test/resources/images"), true); ACCID accid = new ACCID(); for (Iterator<File> iterator = imageFiles.iterator(); iterator.hasNext(); ) { File nextImage = iterator.next(); accid.extract(ImageIO.read(nextImage)); System.out.println(nextImage.getName() + ": " + Arrays.toString(accid.getFeatureVector())); } }