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)