Reputation: 59
In such a game board, I want to detect all the numbers, together with the positions of these numbers. Any ideas about how to do it?
Do there exist any libraries in Python which I can import to recognize these numbers, together with the positions of them on such a game board?
Upvotes: 0
Views: 347
Reputation: 8270
Some results are missing here but you can start with following approach:
Code:
import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = r'c:\Program Files\Tesseract-OCR\tesseract.exe'
img = Image.open('image.png')
for x, ltr in enumerate('abcdefghijklmno'):
for y, nbr in enumerate(range(15, 0, -1)):
x_start = 20+x*30
y_start = 20+y*30
img_crop = img.crop((x_start, y_start, x_start+20, y_start+20))
res = pytesseract.image_to_string(img_crop).replace('\f', '').replace('\n', '')
if res:
print(f'{ltr}{nbr} - {res}')
Output:
b9 - 39
c7 - 44
c6 - 22
d9 - 37
f11 - 31
f10 - 42
f4 - 24
f3 - 23
g11 - 20
h11 - 26
i12 - 25
j11 - 27
j9 - 21
k10 - 28
Upvotes: 1