OCR in the screenshot

I need to convert an image to text. But it's a little easier than it sounds.

The image I'm talking about is not a scanned document or something that is rotated, skewed and up and down. This is a clean screenshot of the game (similar to taking a snapshot of some text in a notebook). I also know exactly how large the text is and where it is located, it is also very easy to remove the background and make it black on white.

The font will always remain unchanged (however, I don’t know which font). so maybe i could teach him to read this particular font?

I also need this to be called from a C # application. so I'm looking for something in C # to say: here is the bitmap (or the path to the bitmap), give me what it says in plain text.

I have already tried this tesseract ocr, but it seems that I am doing something wrong, because it is almost always wrong. The only one who had good results (only a small error with β€œat” becomes β€œt”) was Capture2Text, but I have no idea how to use this in C #.

here is a small sample of what she should be able to read: http://i.imgur.com/PdEGznk.png

+8
c # ocr screenshot
source share
4 answers

I use Tesseract.NET to recognize the image of your sample and got "Evorvze SWOYG"; after rescaling it to 300DPI, received the Bronze Sword.

+5
source share

I just added that the image scaling code is twice as large and it recognizes numbers perfectly!

Bitmap b = new Bitmap(width * 2, height * 2); using (Graphics g1 = Graphics.FromImage((Image)b)) { g1.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g1.DrawImage(newBitmap, 0, 0, width * 2, height * 2); } 
0
source share

I really suggest not trying out up to 300 DPI, this will create a lot of smoothing. Which is not suitable for OCR. Some engines, such as Nuance and ABBYY, are smart enough to know how to handle fonts in images with a resolution of 72 dpi.

The OCR engine in the MODI library uses the old version of Nuance, which will be significantly better than Capture2Text and Tesseract.

0
source share

The idea is that every time new screenshot files appear in a folder, launch tesseract OCR and open them in the file editor.

You can use the script below on Linux or on Windows with WSL (Ubuntu on Windows)

You can leave this running script in the output directory of your favorite output screenshots directory

 #cat wait_for_it.sh inotifywait -m . -e create -e moved_to | while read path action file; do echo "The file '$file' appeared in directory '$path' via '$action'" cd "$path" if [ ${file: -4} == ".png" ]; then tesseract "$file" "$file" sleep 1 gedit "$file".txt & fi done 

You need it installed

 sudo apt install tesseract-ocr sudo apt install inotify-tools 

I use it with Shutter in Ubuntu and with Greenshot on Windows with WSL (Ubuntu on Windows)

0
source share

All Articles