import tesserocr
from PIL import Image

image = Image.open('code.jpg')
image = image.convert('L')
threshola = 127
table = []
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  Image
import subprocess

image = 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())

  

相关文章:

  • 2022-12-23
  • 2021-08-09
  • 2021-04-16
  • 2021-04-05
  • 2021-11-27
猜你喜欢
  • 2022-12-23
  • 2021-09-13
  • 2021-12-05
  • 2021-07-22
相关资源
相似解决方案