[The Python] binarization

https://blog.csdn.net/qq_35531549/article/details/96134760

 

Pretreatment recognition #
# binarized image
from the PIL Import Image
Import OS
the os.chdir ( 'D: \ the OCR')
IMG = Image.open ( 'test.png')

# mode L "of a gray image, each of its represented with 8 bit pixel, 0 represents black and 255 represents white, other numbers represent different shades of gray.
the Img = img.convert ( 'L')
Img.save ( "test1.png")

# custom gray boundaries, this value is larger than the 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
= Img.point Photo (Table, '. 1')
photo.save ( "test2.png")
# picture content identification
Import pytesseract
img_path = 'test2.png'

text=pytesseract.image_to_string(Image.open(img_path))

print(text)

----------------
Disclaimer: This article is CSDN blogger "inch of grass 2130" original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_35531549/article/details/96134760

Guess you like

Origin www.cnblogs.com/shanlinghan/p/12403909.html