OCR for light text on dark background in newest
See original GitHub issuehi, 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();
}
}
} ` 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:71 (48 by maintainers)
Top GitHub Comments
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.
👍