How to ignore special characters in Tesseract OCR

2019-09-20 10:57发布

I have extracted text from image through Tesseract OCR using java. But the output is consisting of some special characters because image contains some symbols.

I want to ignore all the special characters and display just text. Is there any way that i can do that?

1条回答
在下西门庆
2楼-- · 2019-09-20 11:59

In tesseract you can set TessBaseAPI.VAR_CHAR_WHITELIST and TessBaseAPI.VAR_CHAR_BLACKLIST in order to ignore some special characters.

Following would make tesseract only recognize A-Z and digits

String whiteList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
tessBaseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,whiteList);

Next snippet would allow you to recognize everything except for ~ and fl

String blackList = "~fl";
tessBaseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST,blackList );

Also please note that as mentioned in tesseract github issue you can't black or whitelist characters with tesseract 4.0 Alpha LSTM, instead you should train LSTM with characters you expect on your image.

Of course if you want - you can still use 3.* versions of tesseract, its tessdata is located here

查看更多
登录 后发表回答