識別圖中文字

from PIL import Image
import pytesseract

txt = pytesseract.image_to_string('pingjia.png', lang='chi_sim')
print(txt)
print('*'*50)

#二值化然後轉灰度圖像
def c():
    image = Image.open('pingjia.png')
    image=image.convert('L')
    threshold=160
    table=[]
    for i in range(256):
        if i<threshold:
            table.append(0)
        else:
            table.append(1)
    image=image.point(table,'1')
    # image.show()
    txt = pytesseract.image_to_string(image, lang='chi_sim')
    print(txt)
c()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章