question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OCR for light text on dark background in newest

See original GitHub issue

hi, I use TextRecognizer.doOCR() API to detect text from image,but it can’t work in version about sikulixapi-2.0.1.jar,then i pull the source code and build newest version about sikulixapi-2.1.0-SNAPSHOT.jar and sikulix2opencv-4.1.1.jar,however ,it also can’t work ,my test code as following: ` import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException;

import javax.imageio.ImageIO;

import org.sikuli.script.TextRecognizer;

public class TessTest {

public static void main(String[] args) throws IOException {
	 BufferedImage image = ImageIO.read(new File("d:\\zero.png"));
	   try {
		   String text=TextRecognizer.doOCR(image);
		   System.out.println(text);
	} catch (Throwable e) {
		e.printStackTrace();
	}
}

} ` zero and the image is above,the zero can’t be detect all my want to detect text is either number or English alphabet, I set psm to 12 or 13,and i also set tessedit_char_whitelist ,but it seems it still crash. appreciate all your help. thank you reference to : https://github.com/RaiMan/SikuliX1/pull/204 https://github.com/RaiMan/SikuliX1/issues/73#issue-400346304

@RaiMan @balmma @traviscibot @hcientist @MiguelDomingues

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:71 (48 by maintainers)

github_iconTop GitHub Comments

1reaction
balmmacommented, Jan 7, 2020

however my question is why so clear image can’t be recognized in 1920×1080 resolution? 1920×1080,DPI=120

Allright, now we found the problem, it’s related to your high DPI value. (I guess DPI is smaller on your system when you set the resolution to 1440x900?)

SikuliX resizes the image internally to 192 DPI based on the current screen density before passing it to Tesseract. This means that in your case the image is resized by a factor of 1.6 (192 / 120) in my case with 96 DPI the image is resized by a factor of 2 (192 / 96). Seems that Tesseract can only recognize this particular image when it is enlarged enough. That’s why RaiMans initial suggestion to resize the image works.

@RaiMan I’m not sure anymore if resizing the image based on the screen DPI is the best option. Probably it would be better to just always resize the image by a factor of 2 by default and make this factor configurable. IMO the 300 DPI recommendation of Tesseract is rather meant for scanned documents, the resulting font size (height of a capital letter between 20 - 30 px) seems to be more important. In the OP’s zero.png the height of the “0” is 12 px. On his screen with 120 DPI it gets resized to 19.2 px, on a screen with 96 DPI to 24 px which seems to work much better.

0reactions
balmmacommented, Jan 20, 2020

👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

White Text on Black Background - OCR Prep Options
Hi All,. I am wondering about the experiences you have had with OCRing white text on dark backgrounds. After getting a bad OCR...
Read more >
How to recognise white text on dark background – Help Center
We now get a good recognition of white text on a dark blue background without harming the recognition of dark text on a...
Read more >
Reading text with OCR with dark background | Blue Prism ...
Hi, I am trying OCR on a red background image having text in black, but it doesn't give any value, that is the...
Read more >
Unable to read white text on black background using pytesseract
I'm trying to read and get the location of the white text on the black background using pytesseract, but ...
Read more >
Color inversion - Aspose Documentation
When working with white (or light) text on a black (or other dark) background, recognition accuracy may suffer. It can be greatly improved...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found