如何使用OpenCV和Pytesseract从图像中提取文本?
但是这会出现错误-
回溯(最近的调用在最上面): 文件“open.py”,第14行,在 print pytesseract.image_to_string(edges) 文件“/home/sroy8091/.local/lib/python2.7/site-packages/pytesseract/pytesseract.py”,第143行,在image_to_string if len(image.split()) == 4: 属性错误:'NoneType'对象没有属性'split'
import cv2
导入pytesseract库 从PIL库中导入Image模块 导入numpy库的np模块 从matplotlib库中导入pyplot模块
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)
但是这会出现错误-
回溯(最近的调用在最上面): 文件“open.py”,第14行,在 print pytesseract.image_to_string(edges) 文件“/home/sroy8091/.local/lib/python2.7/site-packages/pytesseract/pytesseract.py”,第143行,在image_to_string if len(image.split()) == 4: 属性错误:'NoneType'对象没有属性'split'