使用Python在图像中进行光学字符识别

时间:2018-08-13 10:43:02

标签: python image-processing ocr

我有an image file,Python会读取它并将其转换为十六进制。这里的问题是,即使我给出一个空的空白图像,其给出的十六进制数字也将作为输出。我需要Python仅处理图像中的字母,然后将它们转换为十六进制并将其作为输出。

这是我累的程序

import binascii

filename = 'a.png'
with open(filename, 'rb') as f:
    content = f.read()

print(binascii.hexlify(content))

1 个答案:

答案 0 :(得分:1)

这是OCR(光学字符识别)问题,在堆栈history中已讨论了多次。

Pytesserect轻松做到这一点。

用法:

import pytesserect
from PIL import Image

# Get text in the image
text = pytesseract.image_to_string(Image.open(filename))

# Convert string into hexadecimal
hex_text = text.encode("hex")
相关问题