Simple image recognition using Python (verification code)

Source: Internet
Author: User

This is one of the simplest image recognition, and the image is loaded directly using a Python recognition engine to identifyPass the numbers in the picturePytesseract.image_to_string (image)after recognition, the results are stored in a local TXT file
1 #-*-encoding:utf-8-*-2 Importpytesseract3  fromPILImportImage4 5 classGetimagedate (object):6     defm (self):7Image = Image.open (u"C:\\a.png")8Text =pytesseract.image_to_string (image)9         returntextTen  One     defsaveresulttodocument (self): AText =self.m () -f = open (U"C:\\verification.txt","W") -         Printtext the f.write (str (text)) - f.close () -  -g =getimagedate () +G.saveresulttodocument ()
specifically want to implement the above code needs to install two packages and an engineInstall PYTHON,PIP and configure environment variables prior to installation .All packages are installed via Pip and need to be done in Windows PowerShell and are in the C:\Python27\Scripts directory1. First Package: PytesseractPip Install Pytesseract If there is an installation error, you can change the command to Pip.exe install when the installation is not possible. Pytesseract to install if the PIP is modified to pip.exe the installation succeeds, then all pips below will need to be changed to Pip.exe2. Second package: PIL installationPip install PIL If it fails, you can modify PIP install PILLOW as follows3. Install the recognition engine TESSERACT-OCRDownload TESSERACT-OCR, install the default installation after installation, you need to configure environment variables, add TESSERACT-OCR installation address after system variable path C:\Program Files (x86) \TESSERACT-OCR ; Run the above code after the installation is complete, you will find an error, at this time needThis concludes

Simple image recognition using Python (verification code)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.