To Do OCR in Python to This Image

i try to do OCR in python to this image (the number inside can change)
i try everything
tesseract
EasyOCR
but every method doing a lot of mistake

2233 copy

imge = cv2.imread('2233.png', 0)
imge = cv2.resize(imge, None, fx=0.5, fy=0.5)
config = "--psm 7"
imge = pytesseract.image_to_string(imge, config=config)
print(imge)

Hi @Daniel2344,

Keyboard Maestro has a native action for OCR.

However, when I tried the image you uploaded, I got an error:
image

Hi @peternlewis, what does this warning mean and how to pre-process the image file to get OCR to work?

You might find this discussion illuminating. Which would lead you to invert the image for OCR so it's black on white.

1 Like

The Tesseract library often produces that warning. Keyboard Maestro ignores it if anything else is produced - however if nothing else is produced it allows it through since it might be the case.

In this case, its just not finding anything.

Even inverting it is insufficient, the circle around the outside needs to be removed and it needs to be inverted to get the text to work.

Removing the circle is easily done with cropping.

Keyboard Maestro does not currently have any action to invert an image I'm afraid.

1 Like

No, but if the color scheme is caused by Dark Mode, that's easily addressed.

I can confirm that both inverting colors and cropping are needed.

Here are my tests (see screenshot of my clipboard history. Order: from bottom to top):

  1. Fist to just the inverting colors, KM still shows the warning.
  2. screenshot the characters inside the circle, which I take it to be equivalent to cropping, the characters are correctly OCRed → 25%.
  3. screenshot the original, non-color-inverted character (white character in black background), the OCR result is hey, not 25%.

image

This shows that both color-inverting and cropping are needed.