I. Preparation and code examples
1, PIL, Pytesser, tesseract
(1) Install pil::http://www.pythonware.com/products/pil/(csdn download)
After the download is an EXE, directly double-click the installation, it will automatically install into the C:\Python27\Lib\site-packages,
(In fact, with PIP installed, pip install PIL or pip install pillow It forget, you can check the next look! )
(2) pytesser::http://code.google.com/p/pytesser/, (csdn download)
After the download decompression directly put C:\Python27\Lib\site-packages (depending on the Python path you installed different), at the same time, create a new pytesser.pth, the content is written Pytesser, Note that the content here must be the same name as the Pytesser folder, meaning that the Pytesser folder, Pytesser.pth, and content are the same!
(3) Tesseract OCR engine Download: http://code.google.com/p/tesseract-ocr/(csdn download)
After downloading, unzip, Tessdata folder, use it to replace the Pytesser extracted Tessdata folder. (On the Pytesser folder above)
In fact, as long as the extracted files are copied directly in the past, you will be prompted whether to overwrite, you can directly overwrite. PS: At first I just tessdata copy the past overlay, and finally redefine the script's working path or not full coverage, then OK
Note: To read the verification code picture needs to be saved in C:\Python27\Lib\site-packages\pytesser This directory, that is, pytesser this installation package file, no test does not save where will report what error, have time to try!
Here is the code for the test:
1Rom PytesserImport*2 ImportOS3Os.chdir ('C:\Python27\Lib\site-packages\pytesser')#The working directory under the current script; the equivalent of a CD under the shell4My_math =OS.GETCWD ()5 PrintMy_math6 7Math ='fnord.tif'8im =image.open (Math)9 PrintImage_to_string (IM)
If you do not redefine the script's working path, it will appear with the following error:
Reference:
Http://www.voidcn.com/blog/u014265347/article/p-5036019.html
http://blog.csdn.net/evankaka/article/details/49533493
Python Verification Code identification