Python sample sharing for image recognition

Source: Internet
Author: User
This article mainly describes the Python programming implementation of the image recognition function, involving the Python PIL module installation and use of skills, the need for friends can refer to the following

This paper describes the image recognition function implemented by Python programming. Share to everyone for your reference, as follows:

1. Install PIL, the official no WIN64 bit, pillow replace

Pip Install PILLOW-2.7.0-CP27-NONE-WIN_AMD64.WHL

2. Installing Pytesser

Download Pytesser_v0.0.1.zip, unzip and copy into Python27\lib\site-packges\pytesser path, no pytesser new

Create a new pytesser.pth file in Python27\lib\site-packges\pytesser with the contents of Pytesser

Within the Pytesser, modify the three point

①pytesser.py modified into __init.py__

② modifying pytesser.py


Import Image

Switch


From PIL import Image

Tesseract_exe_name = ' tesseract ' instead of tesseract_exe_name = ' python27\\lib\\site-packges\\pytesser\\tesseract ' note \ Escape

③ installation Tesseract

After the download, find the Tessdata folder, and replace it with Pytesser extracted Tessdata folder.

However, in addition to the test verification code, the remaining system verification code recognition rate is very low.

Test code attached


from pytesser import *from PIL import Image, Imageenhanceim = Image.open (' D:\Python27\Lib\ Site-packages\pytesser\phototest.tif ') im2 = Image.open (R ' D:\Python27\Lib\site-packages\pytesser\fnord.tif ', ' R ') IM3 = Image.open (R ' F:\PROJECT\python\code\Study_1\src\20170424\cp.jpg ', ' R ') #文件读写模式以防报错 # image processing 1:: Black and white processing enhancer = Imageenhance.contrast (im3) image2 = enhancer.enhance (5) image2.show () print image_to_string (image2) #图片处理2: noise reduction processing imgry =   Im3.convert (' L ') #灰度处理 # Grayscale processing on the basis of two value processing threshold = 140table = []for i in range: if I < threshold:table.append (0) Else:table.append (1) out = imgry.point (table, ' 1 ') out.show () Text = image_to_string (out) if Text.isspace (): print "FA ILE "Else:print text#print text 

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.