python picture binarization improve the recognition rate

 
 

  

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) # mode L "of a gray image, which each pixel is represented by 8 bit, 0 represents black and 255 represents white, other numbers represent different gray . the Img = img.convert ( ' L ' ) Img.save (newFilePath) # custom gray limit, greater than the value of black, white value is less than the threshold = 200 is Table = [] for I in Range (256 ): IF I < threshold: table.append (0) the else : table.append ( . 1 ) # image binarization photo = Img.point (table,'1') photo.save(newFilePath)

if __name__ == '__main__':

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

 

 

Original:

After the processing in FIG:

 

Recognition results:

 

Guess you like

Origin www.cnblogs.com/codeDevotee/p/11403096.html