Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tesseract does not recognize single characters

Tags:

ocr

tesseract

How to represent:

  1. Create new image with paint (any size)
  2. Add letter A to this image
  3. Try to recognize -> tesseract will not find any letters
  4. Copy-paste this letter 5-6 times to this image
  5. Try to recognize -> tesseract will find all the letters

Why?

like image 665
artem Avatar asked Mar 09 '12 09:03

artem


People also ask

How accurate is Tesseract?

The following results are presented for Tesseract: the original set of samples achieves a precision of 0.907 and 0.901 recall rate, while the preprocessed set leads to a precision of 0.929 and a recall of 0.928. Thompson et al.

What is the difference between Pytesseract and Tesseract?

Tesserocr is a Python wrapper around the Tesseract C++ API. Whereas Pytesseract is a wrapper for the tesseract-ocr CLI. Therefore with Tesserocr you can load the model at the beginning or your program, and run the model separately (for example in loops to process videos).

How does Tesseract recognize text from images?

Optical Character Recognition (OCR) is a technology that is used to recognize text from images. It can be used to convert tight handwritten or printed texts into machine-readable texts. To use OCR, you need to install and configure tesseract on your computer. First, download the Tesseract OCR executables here.

What is OSD in Pytesseract?

The OSD mode provides us with meta-data of the text in the image, including both estimated text orientation and script/writing system detection. The text orientation refers to the angle (in degrees) of the text in the image.


2 Answers

You must set the "page segmentation mode" to "single char".

For example, in Android you do the following:

api.setPageSegMode(TessBaseAPI.pageSegMode.PSM_SINGLE_CHAR);
like image 140
Marco Bonifazi Avatar answered Oct 21 '22 04:10

Marco Bonifazi


python code to do that configuration is like this:

import pytesseract
import cv2
img = cv2.imread("path to some image")
pytesseract.image_to_string(
     img, config=("-c tessedit"
                  "_char_whitelist=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
                  " --psm 10"
                  " -l osd"
                  " "))

the --psm flag defines the page segmentation mode.

according to documentaion of tesseract, 10 means :

Treat the image as a single character.

so to recognize a single character you just need to use : --psm 10 flag.

like image 31
Shahryar Saljoughi Avatar answered Oct 21 '22 04:10

Shahryar Saljoughi