python圖片二值化提高識別率


 
         

  

import cv2
from PIL import Image
from pytesseract import pytesseract
from PIL import ImageEnhance
import re
import string



def
createFile(filePath,newFilePath): img = Image.open(filePath) # 模式L”為灰色圖像,它的每個像素用8個bit表示,0表示黑,255表示白,其他數字表示不同的灰度。 Img = img.convert('L') Img.save(newFilePath) # 自定義灰度界限,大於這個值為黑色,小於這個值為白色 threshold = 200 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) # 圖片二值化 photo = Img.point(table, '1') photo.save(newFilePath)

if __name__ == '__main__':

createFile(r'1.bmp',r'newTest.png')

 

 

原圖:

處理過后的圖:

 

識別結果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM