E
E
expp2020-06-25 12:36:13
Python
expp, 2020-06-25 12:36:13

How can digits be recognized with tesseract?

Good morning. I tried to write a program that would recognize text in a certain area (the code is presented below). But the program does not recognize the numbers in the picture. I have given an example of numbers below. There was an idea that this is such a text font, but most likely these numbers are made up of lines (well, just as numbers are drawn, so here). The essence of the problem is that tesseract does not recognize these characters, they are numbers. I hope for your help, thanks)
Code:

import pyautogui
import time
import numpy as np
import pyscreenshot as ImageGrab
import cv2
import os
import pytesseract

time.sleep(5)
filename = 'Image.png'
x = 1
last_time = time.time()

while(True):
  
  screen = np.array(ImageGrab.grab(bbox=(671, 296, 1129, 423)))
  print('loop took {} seconds'.format(time.time()-last_time))
  last_time = time.time()
  cv2.imshow('window', cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
  cv2.imwrite(filename, screen)
  x = x + 1
  print(x)
  if x == 2:
    cv2.destroyAllWindows()
    break

img = cv2.imread('Image.png')
pytesseract.pytesseract.tesseract_cmd = r'C:/Users/Admin/AppData/Local/Tesseract-OCR/tesseract.exe'
text = pytesseract.image_to_string(img)
print(text)


An example of a picture with numbers (captcha):
5ef470079971e706368737.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2020-06-25
@expp

This task, as already written by Vladimir Kuts , can be solved using algorithms, but if you want it with tesseract, then:
1. You need to clear the image: remove the outer frame, make a greyscale image, etc., etc.
2. Choose a wrapper for tesseracta that will work best with your data.
Here is a little more detail - I wrote a long time ago, but during this time nothing fundamental has changed.

V
Vladimir Kuts, 2020-06-25
@fox_12

You have such numbers - that you can do without a tesseract

If you can, then please give a link to an article or any resource with this information, or tell us yourself if you have time and desire

Simple logic. Slice the image into identical rectangles and poke at a few key coordinates specific to numbers
5ef48501d4782332889281.png
At point "1" 1, 3, and 0 will be black, at "2" 3, 4, and 1, and so on.
and make a condition - if in "1" - black, in "2" - black, in "3" - white ... - then the figure found is "3"
if in "1" - black, in "2" - white, in "3" - white ... - then the digit found is "0"
if in "1" - black, in "2" - black, in "3" - black ... - then the digit found is " 1"
etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question