Simple image recognition (Verification Code) using Python and python Image Recognition

Source: Internet
Author: User

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.

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.