Modifying a read and readLine Method

Asked by sibusiso mbambo

Hi,

I'm trying to read values displaying in a website. The values I'm reading are changing multiple times a second for example 2.01, 9.11, 12.43 and so and I read these values every second.

The image i'm capturing have red values in colour and the background have stripes (lines). I'm using Tesseract Tess4J-4.5.4 in java and I use the below methods which modify the image and text background, remove stripes in an image and I get 100 % results all the time.

The challenge is I have to take a screenshot every second and the BufferedImage
is slowing my problem considerably and stopping it with full memory exception.

I try to use the flush() method to flush the BufferedImage but I still get the same problem.

I now use SikuliXapi Version-2.0.5 for Windows. I use these methods region.text() or region.textLine() and the slowing down of the program has improved considerably and it almost gone to the point that I decided to use Sikuli alone. The
challenge now is that the results I get from Sikuli are about 70 % and based on my program I need the results to be 100 % all the time.

Now my question is using Sikuli and looking at my below code, how can I add the "CHANGE IMAGE BACKGROUND AND TEXT" and "REMOVING STRIPES ON AN IMAGE" to my sikuli code so I can get the
100 % resuls? Is there a way to do this kind of modification in Sikuli?

MY CODE:

//METHOD START
private static void readValue() throws IOException, AWTException, InterruptedException {

Tesseract tessEndValue = new Tesseract();
tessEndValue.setDatapath("C:\\Tess4J\\tessdata");
tessEndValue.setTessVariable("user_defined_dpi", "300");

Rectangle regionEndValue = new Rectangle(eVx,eVy,eVh,eVw);
BufferedImage readEndValueimage = robot.createScreenCapture(regionEndValue);

//CHANGE IMAGE BACKGROUND AND TEXT
for (int a = 0; a < readEndValueimage.getWidth(); a++) {
for (int b = 0; b < readEndValueimage.getHeight(); b++) {
int rgba = readEndValueimage.getRGB(a, b);
Color col = new Color(rgba, true);
col = new Color(255 - col.getRed(), 255 - col.getGreen(), 255 - col.getBlue());
readEndValueimage.setRGB(a, b, col.getRGB());
}}

//REMOVING STRIPES ON AN IMAGE
Color lightest = Color.BLACK;
Color darkest = Color.WHITE;
for (int x = 0; x < readEndValueimage.getWidth(); x += 8) {
for (int y = 0; y < readEndValueimage.getHeight(); y += 8) {
Color color = new Color(readEndValueimage.getRGB(x, y));
if (isDarker(color, darkest)) darkest = color;
if (isLighter(color, lightest)) lightest = color;
}}

for (int x = 0; x < readEndValueimage.getWidth(); x++) {
for (int y = 0; y < readEndValueimage.getHeight(); y++) {
Color color = new Color(readEndValueimage.getRGB(x, y));
if (differenceSquared(color, lightest) < differenceSquared(color, darkest)) {
readEndValueimage.setRGB(x, y, lightest.getRGB());
}
else {
readEndValueimage.setRGB(x, y, darkest.getRGB());
}
}}

String endValue = tessEndValue.doOCR(readEndValueimage);

}
catch(Exception e) {
System.out.println("Read End Value A Try Failed");
}
}
//METHOD ENDS
private static boolean isLighter(Color color, Color lightest) {
return ( (color.getRed() + color.getGreen() + color.getBlue()) > (lightest.getRed() +
lightest.getGreen() + lightest.getBlue()) );
}
private static boolean isDarker(Color color, Color darkest) {
return ( (color.getRed() + color.getGreen() + color.getBlue()) < (darkest.getRed() +
darkest.getGreen() + darkest.getBlue()) );
}

private static double differenceSquared(Color a, Color b) {
return Math.pow(a.getRed() - b.getRed(), 2) + Math.pow(a.getGreen() - b.getGreen(), 2) +
Math.pow(a.getBlue() - b.getBlue(), 2);
}

Thank you!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
sibusiso mbambo
Solved:
Last query:
Last reply:
Revision history for this message
sibusiso mbambo (emmabura) said :
#1

I solved the problem .