【发布时间】:2016-11-04 16:54:40
【问题描述】:
如何使用opencv和pytesseract从图片中提取文字?
import cv2
导入 pytesseract 从 PIL 导入图像 将 numpy 导入为 np from matplotlib import pyplot as plt
img = Image.open('test.jpg').convert('L')
img.show()
img.save('test','png')
img = cv2.imread('test.png',0)
edges = cv2.Canny(img,100,200)
#contour = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
#print pytesseract.image_to_string(Image.open(edges))
print pytesseract.image_to_string(edges)
但这会出错-
Traceback(最近一次调用最后一次): 文件“open.py”,第 14 行,在 打印 pytesseract.image_to_string(edges) 文件“/home/sroy8091/.local/lib/python2.7/site-packages/pytesseract/pytesseract.py”,第 143 行,位于 image_to_string 如果 len(image.split()) == 4: AttributeError: 'NoneType' 对象没有属性 'split'
【问题讨论】: