2

I'm trying to recognize some text with pytesseract, but before that I have to turn the picture I have into a binary one. Note that I first resize the picture to make it easier to read for pytesseract.

See below the original picture, the resized one, my code and the result I get, so you can understand my issue..

Original picture

image = cv2.imread('original.png',0)
image = cv2.resize(image,None,fx=2,fy=2,interpolation=cv2.INTER_CUBIC)
cv2.imwrite("resized.png", image)

thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
result = 255 - thresh
cv2.imwrite("after_threshold.png", result)

Resized picture

Picture after threshold

Thank you for your help :)

nathancy
  • 42,661
  • 14
  • 115
  • 137

1 Answers1

1

If you remove the resize, it seems to work

enter image description here enter image description here

Output from Pytesseract

32 Force

120 Initiative
Prospection

25 agilité

53 Vitalité

5 Dommages

1 Résistance Neutre
1 Portée

7% Résistance Feu
import cv2
import pytesseract

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

image = cv2.imread('1.png', 0)
thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
result = 255 - thresh 

data = pytesseract.image_to_string(result, lang='eng',config='--psm 6')
print(data)

cv2.imshow('thresh', thresh)
cv2.imshow('result', result)
cv2.waitKey()
nathancy
  • 42,661
  • 14
  • 115
  • 137