2017-09-18 49 views
-4

我想將此url下載轉換爲gif。 http://t.51chuli.com/contact/d91779cced1ade729yz45q72bn3o5o1z.gif如何將GIF轉換爲字符串?

到PHONE_NUM串

我能做些什麼呢? 我的代碼是:

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 

,但沒有輸出

+1

不要截圖你的代碼。將其作爲文本發佈在您的問題中。 – khelwood

回答

0

我有想法:

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(' ','')