欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python pytesseract库的实例用法

程序员文章站 2022-03-09 10:51:13
说明1、pytesseract需要与安装在本地的tesseract-ocr.exe文件一起使用。2、需要注意的是,安装时必须选择中文包,默认只支持英文识别。安装命令pip install pytess...

说明

1、pytesseract需要与安装在本地的tesseract-ocr.exe文件一起使用。

2、需要注意的是,安装时必须选择中文包,默认只支持英文识别。

安装命令

pip install pytesseract

实例

import pytesseract
from pil import image
text = pytesseract.image_to_string(image.open(r"d:\desktop\39dee621-40ea-4ad1-90cc-79eb51d39347.png"))
print(text)

识别结果输出

using tesseract ocr with python
# import the necessary packages
from pil import image
import pytesseract
import ergperse
import cv2
import os
 
# construct the argument parse and parse the arguments
ap = argparse.argunentparser()
ap.add_argument("-i", "--image", required-true,
help="path to input image to be ocr'd")
ap.add_argument("-p", "--preprocess", typesstr, default="thresh",
helpe"type of preprocessing to be done")
args = vars (ap.parse_args())

实例扩展:

python使用pytesseract库识别图片文字

准备

首先需在本机安装tesseract客户端,然后安装pytesseract库:

pip install pytesseract

没安装过pil的也要安装一下,因为所调用的第一个参数是由image类返回:

pip install pillow

实例

import pytesseract
from pil import image

img = image.open("d://aa.jpg")
text = pytesseract.image_to_string(img, lang="chi_sim")
print(text)

到此这篇关于python pytesseract库的实例用法的文章就介绍到这了,更多相关python pytesseract库是什么内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!