Simple image recognition (Verification Code) using Python and python Image Recognition
This is the simplest image recognition method. After loading images, you can use a Python recognition engine for recognition.
Identify the number in the image through pytesseract. image_to_string (image) and save the result to the local txt file.
#-*-encoding:utf-8-*- import pytesseract from PIL import Image class GetImageDate(object): def m(self): image = Image.open(u"C:\\a.png") text = pytesseract.image_to_string(image) return text def SaveResultToDocument(self): text = self.m() f = open(u"C:\\Verification.txt","w") print text f.write(str(text)) f.close() g = GetImageDate() g.SaveResultToDocument()
To implement the above Code, you need to install two packages and one engine.
Install Python and pip and configure environment variables before installation.
All packages are installed using pip, which must be performed in windows PowerShell and under the C: \ Python27 \ Scripts directory.
1. First package: pytesseract
pip install pytesseract
If an installation error occurs, you can change the command to pip.exe install pytesseract when the installation fails.
If pip.exeis successfully installed, change all Pips in the following text to pip.exe.
2. Second Package: PIL Installation
pip install PIL
If it fails, modify pip install PILLOW as follows:
3. Install the recognition engine tesseract-ocr
Download tesseract-ocr for default installation
After installation, You need to configure the environment variables. After the system variable path, add the installation address C: \ Program Files (x86) \ tesseract-ocr for Tesseract-OCR;
Run the above Code after everything is installed. An error is reported.
So far.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.