package dataBase;

import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.WritableRaster;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;

import javax.imageio.ImageIO;

import dataBase.subPicture.SubPicture;


import util.simpleIO.Out;

public class Test_DataBase3_Search {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws ClassNotFoundException 
	 */
	public static void main(String[] args) throws IOException, ClassNotFoundException {
		
		Out.pl("> Load DB:");
		String folder = "./testdaten/alt/";
		ObjectInputStream obj_in = new ObjectInputStream( new FileInputStream(folder+"DataBase0.db") );
		Object obj = obj_in.readObject();  
		DataBase db = (DataBase) obj;
		Out.pl("  "+db.toString());
		//_________________________________________
		
		Out.pl("> Search:");
		//File imageFile = new File("testdatenfinalImg.jpg");
		File imageFile = new File(folder+"1.jpg");
		BufferedImage image = ImageIO.read(imageFile);
		
		SubPicture searchPic = new SubPicture(imageFile, image);
		ArrayList<SubPicture> results = db.search(searchPic);
		
		Out.pl(""+results.size()+" results:");
		Out.pl(results.toString());
	}

	/**
	 * 
	 * @param pixel
	 */
	private static void add(int[] pixel) {
		// TODO Auto-generated method stub
	}

}
