Anil B
Anil B

Reputation: 101

pytesseract - Invalid resolution 0 dpi

I am using pytesseract v5.0 and I am rotating the image with OpenCV and then passing it to pytesseract.image_to_osd(). There are some images that work with the image_to_osd, but other images do not and the program gives me the following error: TesseractError: (1, 'Tesseract Open Source OCR Engine v5.0.0-alpha.20201127 with Leptonica Warning: Invalid resolution 0 dpi. Using 70 instead. Estimating resolution as 179 Warning. Invalid resolution 0 dpi. Using 70 instead. Too few characters. Skipping this page Error during processing.') I am using python 3.9.5.

Please share the solution / sample code to fix this issue.

Upvotes: 10

Views: 5774

Answers (1)

Esraa Abdelmaksoud
Esraa Abdelmaksoud

Reputation: 1699

I've been facing this error for a quite long time but finally realized the reason.

  1. Tesseract OSD seems to get the correct image rotation if it's only 0,90,180, or 270.
  2. If you're using OpenCV or Pillow to read your image, it's likely to get the error above.
  3. If you view Tesseract parameters, you will notice something called "Min_characters_to_try" which is the minimum number of characters to run OSD. It's set to 50 by default, which might be too much for you. So, we have to reduce it.

What you can do is cropping your background to make your object have one of the angles stated above. Then, pass your image file directly to Tesseract and reduce the min_characters_to_try like the following:

osd = pytesseract.image_to_osd(r'D:\image.jpg',config='--psm 0 -c min_characters_to_try=5')

Upvotes: 11

Related Questions