import tesserocrfrom PIL import Imageimage = Image.open('code.jpg')image = image.convert('L')threshola = 127table = []for i in range(256): if i < threshola: table.append(0) else: table.append(1)image = image.point(table, '1')image.show()result = tesserocr.image_to_text(image)print(result)
from PIL import Imageimport subprocessimage = Image.open('code.jpg')image = image.point(lambda x: 0 if x<127 else 255)image.save('code2.jpg')subprocess.call(["tesseract", 'code2.jpg', "output"])with open('output.txt', 'r') as f: print(f.read())