import tesserocr from PIL import Image
ima = Image.open('1.png') image=ima.resize((480,200),Image.ANTIALIAS) image = image.convert('L')
这个是二值化阈值
threshold = 160 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1)
通过表格转换成二进制图片,1的作用是白色,不然就全部黑色了
image = image.point(table, "1")
print(tesserocr.image_to_text(image)[:5]) # print ocr text from image