导入
import pytesseract, base64
from ioimport BytesIO
from PILimport Image
str 转为Image
# str 转 bytes
byte_data = base64.b64decode(string)
# bytes 转 BytesIO
img_data = BytesIO(byte_data)
# BytesIO 转 Image
img = Image.open(img_data)
img= Image.open(img_data)
imgShow = img.show()
#### str = pytesseract.image_to_string(Image.open(img), lang='eng')
str = pytesseract.image_to_string(img, lang='eng')
print(str)
Image转为str
img = Image.open()
# 创建一个字节流管道
imgByteArr = BytesIO()
# 将图片数据存入字节流管道, format可以按照具体文件的格式填写
img.save(imgByteArr, format='png')
# 从字节流管道中获取二进制
image_bytes = imgByteArr.getvalue()
# bytes 转 str
string = base64.b64encode(image_bytes).decode('utf8')