请问python中的tesserocr识别gif图片问题?

各位大神好,我想转换一个gif图片到字符串,尝试多次未果,请教各位大神,如何写?

import requests
from PIL import Image
import tesserocr

img = requests.get(url='http://t.51chuli.com/contact/d91779cced1ade729yz45q72bn3o5o1z.gif')
with open('image.gif','wb') as f:
    f.write(img.content)

pil = Image.open('image.gif')
text = tesserocr.image_to_text(pil)
print text

打印结果为空,请问怎么样写才能解析???

阅读 8k
2 个回答

我已能够解析出此手机号

#!/usr/bin/env python
# coding=utf-8
import sys
from pytesseract import *
import requests
import os
import re
from PIL import Image
from PIL import ImageEnhance
import pkg_resources
url = 'http://t.51chuli.com/contact/d91779cced1ade729yz45q72bn3o5o1z.gif'
html = requests.get(url)
with open('vercode.gif', 'wb') as f:
    f.write(html.content)
    f.flush()
    os.fsync(f.fileno())
if os.path.isfile('vercode.gif'):
    image = Image.open('vercode.gif')
    image = image.convert('L')
    threshold = 250 
    initTable = lambda x:0 if x < threshold else 1
    binaryImage = image.point(initTable, '1')
    vcode = image_to_string(binaryImage, lang="eng", config='-psm 7')
    print vcode.encode('utf-8').replace(' ','')

应该是 leptonica 在解析图片时分辨率的问题。

$ convert image.gif image.png
$ tesseract image.png output
Tesseract Open Source OCR Engine v3.05.00 with Leptonica
Warning. Invalid resolution 0 dpi. Using 70 instead.
Empty page!!
Empty page!!
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题