2017-09-18 1 views
-4

나는이 URL 다운로드를 gif로 변환하고 싶다. PHONE_NUM 문자열어떻게 GIF를 문자열로 변환 할 수 있습니까?

http://t.51chuli.com/contact/d91779cced1ade729yz45q72bn3o5o1z.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 

하지만 아무것도 출력

+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(' ','') 
관련 문제