Sunday, June 30, 2019

Read text on Image file by using Tess4J Selnium Java


package tesss;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
/*<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>4.3.1</version>
</dependency>*/
public class Tesss {
public static void main(String[] args) throws TesseractException, InterruptedException {
/*
* File src = new File("C:\\OCR\\tess.png"); Tesseract tesseract = new
* Tesseract(); String text = tesseract.doOCR(src);
* System.out.println(text);
*/
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\Mutturaj\\muttu11\\muttu11\\Drivers\\chromedriver.exe");
ChromeOptions ops = new ChromeOptions();
ops.addArguments("--disable-notifications");
WebDriver driver = new ChromeDriver(ops);
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.get("https://www.irctc.co.in/nget/train-search");
driver.findElement(By.id("loginText")).click();
Thread.sleep(5000);
File file = driver.findElement(By.id("captchaImg")).getScreenshotAs(OutputType.FILE);
// C:\\OCR\\tess.png"
String str = new Tesseract().doOCR(file);
String data="C:\\Users\\diya-mutturajh\\test\\tessdata";
//Set path for yout tessdata folder
tesseract.setDatapath(data);
System.out.println(str);
str = str.split("below")[1];
System.out.println(str);
driver.quit();
}
}
view raw Tesss.java hosted with ❤ by GitHub

Saturday, June 29, 2019

Reading texts on the image by using Apache Tess4j


import java.io.File;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
/*<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>4.3.1</version>
</dependency>*/
public class Tesss {
public static void main(String[] args) throws TesseractException {
/*File src = new File("C:\\OCR\\tess.png");
Tesseract tesseract = new Tesseract();
String text = tesseract.doOCR(src);
System.out.println(text);*/
System.out.println(new Tesseract().doOCR(new File("C:\\OCR\\tess.png")));
}
}
view raw Tesss.java hosted with ❤ by GitHub