Improving image quality for Tesseract Tess4j?

283 Views Asked by At

On the website where I screenshoted the image the numbers will change continuously.

What I'm trying to do is to read the image text(which is numbers, dot and X on the image) using Tesseract, tess4j java.

The problem is I'm getting inconsistent results, sometimes I get letters sometimes letters with numbers.

After I blacklisted letters excerpts the letter X and special character . I now get 4.0 if I'm not getting the correct results from the picture.

I added a code below to GrayScale the image but still I'm getting the same inconsistent results.

import java.awt.*; 
import java.awt.image.BufferedImage; 
import java.io.*; 
import javax.imageio.ImageIO; 

public class GrayScalingImage { 
public static void main(String args[]) throws Exception { 
try { 
File inputImage = new File("image.jpg"); BufferedImage image = ImageIO.read(inputImage);

for(int i=0; i<image.getHeight(); i++) { 
for(int j=0; j<image.getWidth(); j++) { 
Color color = new Color(image.getRGB(j, i));
int red = (int)(color.getRed() * 0.299); 
int green = (int)(color.getGreen() * 0.587); 
int blue = (int)(color.getBlue() * 0.114); 
Color newColor = new Color(red+green+blue, red+green+blue,red+green+blue);
image.setRGB(j, i, newColor.getRGB());
  }
} 

File ouptut = new File("newImage.jpg"); ImageIO.write(image, "jpg", ouptut); 
 } 
catch (Exception e) {
    } 
   } 
 }
0

There are 0 best solutions below