package macro;

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

public class Text {
	public static String getFromSquare(int left, int top, int right, int bottom) {
		BufferedImage bImage;
		try {
			Robot robot = new Robot();
			Tesseract t = new Tesseract();
			bImage = robot.createScreenCapture(new Rectangle(left, top,
					Math.abs(left - right), Math.abs(top - bottom)));
//			ImageIO.write(bImage, "PNG", new File("Images/test.png"));
			t.setVariable("load_freq_dawg", "false");
			t.setVariable("load_system_dawg", "false");
			return t.doOCR(bImage);
		} catch (AWTException | TesseractException e) {
			e.printStackTrace();
			return null;
		}
	}
}
