package org.genericsystem.cv;

import java.util.stream.Collectors;

import org.opencv.core.Core;

public class HistogramComparator {

	static {
		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	}

	private final static String classImgRepertory = "png";

	public static void main(String[] args) {
		Tools.classImgsStream(classImgRepertory, "image-3.png", "image3-3.png", "image3-1.png", "image3-4.png").forEach(
				img -> System.out.println("Index of most similar image : " + img.findBestHisto(Tools.classImgsStream(classImgRepertory, "image3-4.png", "image3-1.png", "image3-3.png", "image-3.png").collect(Collectors.toList()))));

	}
}

@@ -40,30 +40,194 @@
 ava.
-util.stream.Collectors
+io.IOException;%0Aimport java.nio.file.DirectoryStream;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0Aimport java.util.ArrayList;%0Aimport java.util.List
 ;%0A%0Ai
@@ -458,341 +458,916 @@
 %7B%0A%09%09
-Tools.classImgsStream(classImgRepertory, %22image-3.png%22, %22image3-3.png%22, %22image3-1.png%22, %22image3-4.png%22).forEach(%0A%09%09%09%09img -%3E System.out.println(%22Index of most similar image : %22 + img.findBestHisto(Tools.classImgsStream(classImgRepertory, %22image3-4.png%22, %22image3-1.png%22, %22image3-3.png%22, %22image-3.png%22).collect(Collectors.toList()))));%0A
+List%3CPath%3E directories = new ArrayList%3C%3E();%0A%09%09List%3CImg%3E imgs = new ArrayList%3C%3E();%0A%09%09try (DirectoryStream%3CPath%3E directoryStream = Files.newDirectoryStream(Paths.get(%22.%22, %22classes%22), Files::isDirectory)) %7B%0A%09%09%09for (Path path : directoryStream) %7B%0A%09%09%09%09directories.add(path);%0A%09%09%09%09ImgClass imgClass = new ImgClass(path.toString());%0A%09%09%09%09imgs.add(imgClass.getClassModel() != null ? imgClass.getClassModel() : imgClass.getMean());%0A%09%09%09%09System.gc();%0A%09%09%09%09System.runFinalization();%0A%09%09%09%7D%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09throw new IllegalStateException(e);%0A%09%09%7D%0A%09%09for (int i = 0; i %3C directories.size(); i++) %7B%0A%09%09%09Path path = directories.get(i);%0A%09%09%09System.out.println(%22%5Cn======================= Images of class: %22 + path);%0A%09%09%09Tools.classImgsStream(path.toString()).forEach(img -%3E %7B%0A%09%09%09%09System.out.println(%22Best histogram: %22 + directories.get(img.findBestHisto(imgs)));%0A%09%09%09%09System.gc();%0A%09%09%09%09System.runFinalization();%0A%09%09%09%7D);%0A%09%09%7D
 %0A%09%7D%0A

Test histogram comparator on classified files