Use pytesseract OCR to recognize text from an image

后端 未结 6 753
北恋
北恋 2020-11-30 20:02

I need to use Pytesseract to extract text from this picture:

and the code:

from PIL import Image, ImageEnhance, ImageFilter
import pytesseract
         


        
6条回答
  •  攒了一身酷
    2020-11-30 20:51

    To extract the text directly from the web, you can try the following implementation (making use of the first image):

    import io
    import requests
    import pytesseract
    from PIL import Image, ImageFilter, ImageEnhance
    
    response = requests.get('https://i.stack.imgur.com/HWLay.gif')
    img = Image.open(io.BytesIO(response.content))
    img = img.convert('L')
    img = img.filter(ImageFilter.MedianFilter())
    enhancer = ImageEnhance.Contrast(img)
    img = enhancer.enhance(2)
    img = img.convert('1')
    img.save('image.jpg')
    imagetext = pytesseract.image_to_string(img)
    print(imagetext)
    

提交回复
热议问题