码迷,mamicode.com
首页 > 编程语言 > 详细

Python调用Tesseract-OCR和Zxing完成图片OCR识别和二维码解码

时间:2017-02-14 16:54:38      阅读:1788      评论:0      收藏:0      [点我收藏+]

标签:rar   os.path   tar   jpg   ring   pat   otf   library   nbsp   

 

先贴代码:

# 1.Install tesseract-ocr*.exe from http://jaist.dl.sourceforge.net/project/tesseract-ocr-alt/tesseract-ocr-setup-3.02.02.exe
# 2.Install pillow as"pip install form *.whl"
# 3.Install pytesseract as"pip install form *.whl"
import os.path
import pytesseract
from PIL import Image
from jpype import *
##################################################### Tesserace-ocr #################################################### #image = Image.open(r"D:\Project\AI\1.MachineLearning\A.Tensorflow\2.Python_Prj\FirstPython\processed_7039.png") image = Image.open(r"D:\Project\AI\1.MachineLearning\A.Tensorflow\2.Python_Prj\FirstPython\OCR2.png") code = pytesseract.image_to_string(image) code = code.replace( , ‘‘); code = code.replace(-, ‘‘); code = code.replace(\r, ‘‘); code = code.replace(\n, ‘‘); print(code) ##################################################### Zxing Decode ##################################################### # Start jvm jarpath = os.path.join(os.path.abspath(.), D:/Project/AI/1.MachineLearning/A.Tensorflow/2.Python_Prj/FirstPython/) startJVM("C:/Program Files/Java/jre6/bin/server/jvm.dll", "-ea", ("-Djava.class.path=%s" % (jarpath + "javase-2.2.jar" + ";" + jarpath + "core-2.2.jar"))) # Load the useful library classes File = JClass("java.io.File") BufferedImage = JClass("java.awt.image.BufferedImage") ImageIO = JClass("javax.imageio.ImageIO") BinaryBitmap = JClass("com.google.zxing.BinaryBitmap") DecodeHintType = JClass("com.google.zxing.DecodeHintType") LuminanceSource = JClass("com.google.zxing.LuminanceSource") BufferedImageLuminanceSource = JClass("com.google.zxing.client.j2se.BufferedImageLuminanceSource") MultiFormatReader = JClass("com.google.zxing.MultiFormatReader") NotFoundException = JClass("com.google.zxing.NotFoundException") Result = JClass("com.google.zxing.Result") HybridBinarizer = JClass("com.google.zxing.common.HybridBinarizer") Hashtable = JClass("java.util.Hashtable") # Do the qrcode decode image = ImageIO.read(File("D:/Project/AI/1.MachineLearning/A.Tensorflow/2.Python_Prj/FirstPython/Qrcode1.jpg")) source = BufferedImageLuminanceSource(image) bitmap = BinaryBitmap(HybridBinarizer(source)) hints = Hashtable() hints.put(DecodeHintType.CHARACTER_SET, "GBK") result = MultiFormatReader().decode(bitmap, hints) print(result) # Shutdown JVM shutdownJVM()

 

Python调用Tesseract-OCR和Zxing完成图片OCR识别和二维码解码

标签:rar   os.path   tar   jpg   ring   pat   otf   library   nbsp   

原文地址:http://www.cnblogs.com/jayhust/p/6398318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!