This article mainly describes the Python programming implementation of the image recognition function, involving the Python PIL module installation and use of skills, the need for friends can refer to the following
This paper describes the image recognition function implemented by Python programming. Share to everyone for your reference, as follows:
1. Install PIL, the official no WIN64 bit, pillow replace
Pip Install PILLOW-2.7.0-CP27-NONE-WIN_AMD64.WHL
2. Installing Pytesser
Download Pytesser_v0.0.1.zip, unzip and copy into Python27\lib\site-packges\pytesser path, no pytesser new
Create a new pytesser.pth file in Python27\lib\site-packges\pytesser with the contents of Pytesser
Within the Pytesser, modify the three point
①pytesser.py modified into __init.py__
② modifying pytesser.py
Import Image
Switch
From PIL import Image
Tesseract_exe_name = ' tesseract ' instead of tesseract_exe_name = ' python27\\lib\\site-packges\\pytesser\\tesseract ' note \ Escape
③ installation Tesseract
After the download, find the Tessdata folder, and replace it with Pytesser extracted Tessdata folder.
However, in addition to the test verification code, the remaining system verification code recognition rate is very low.
Test code attached
from pytesser import *from PIL import Image, Imageenhanceim = Image.open (' D:\Python27\Lib\ Site-packages\pytesser\phototest.tif ') im2 = Image.open (R ' D:\Python27\Lib\site-packages\pytesser\fnord.tif ', ' R ') IM3 = Image.open (R ' F:\PROJECT\python\code\Study_1\src\20170424\cp.jpg ', ' R ') #文件读写模式以防报错 # image processing 1:: Black and white processing enhancer = Imageenhance.contrast (im3) image2 = enhancer.enhance (5) image2.show () print image_to_string (image2) #图片处理2: noise reduction processing imgry = Im3.convert (' L ') #灰度处理 # Grayscale processing on the basis of two value processing threshold = 140table = []for i in range: if I < threshold:table.append (0) Else:table.append (1) out = imgry.point (table, ' 1 ') out.show () Text = image_to_string (out) if Text.isspace (): print "FA ILE "Else:print text#print text