如何在图像中使用pytesseract从图像获取文本

时间:2019-02-04 17:08:49

标签: python python-3.x image ocr python-tesseract

我需要使用pytesseract从这张图片中提取文本。这个有可能? 图片:

“ [1]:https://i.stack.imgur.com/tC2FN.jpg

“ [2]:https://i.stack.imgur.com/zeShg.jpg

“ [3]:https://i.stack.imgur.com/NfnZj.jpg

“ [4]:https://i.stack.imgur.com/SH9lU.jpg

“ [5]:https://i.stack.imgur.com/ZYmdy.jpg

“ [6]:https://i.stack.imgur.com/0LzVu.jpg

“ [7]:https://i.stack.imgur.com/rYcLW.jpg

“ [8]:https://i.stack.imgur.com/eaBmB.jpg

代码:

import pytesseract
from PIL import Image, ImageEnhance, ImageFilter

im = Image.open("4.jpg") # the second one 
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
im.save('4temp.jpg')
text = pytesseract.image_to_string(Image.open('4temp.jpg'))
print(text)

解码文字:

  

1-EN
  2- f-ybizc
  3- CALE NGS
  4- [空白]

谢谢!

0 个答案:

没有答案