如何使用pytesseract从小册子图像中提取文本

时间:2019-06-07 05:53:48

标签: python python-tesseract

我尝试从小册子图像中提取文本:

brochure image

代码:

import cv2
import pytesseract
from PIL import Image

im_folder = 'img_path'
im_gray = cv2.imread(im_folder+'/'+'big-bazaar-wed-offer-may-21-2014.png', cv2.IMREAD_GRAYSCALE)

#converting image to binary image
(thresh, im_bw) = cv2.threshold(im_gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

#enhancing the image size
img = cv2.resize(im_bw,None,fx=4,fy=4, interpolation=cv2.INTER_AREA)
cv2.imwrite('im_enhance.png',img)

#Text extraction
text = pytesseract.image_to_string(Image.open('im_enhance.png'))
print(text)

由于这是一张小册子图像,所以我将其转换为二进制图像并对其进行了增强,以获得更好的OCR结果。

我可以使用此代码提取文本,但是某些文本尤其是金额/价格无法提取。

我应该进行哪些更改才能提取所有文本?

0 个答案:

没有答案