图片是这样的:
我的代码:
[Python] 纯文本查看 复制代码 import pytesseract
from PIL import Image
import requests
from io import BytesIO
print('开始')
# img = Image.open("D:\\Files\\python\\img_to_str\\test2.jpg")
# 打开
img1 = Image.open(BytesIO(requests.get(
"https://img.alicdn.com/bao/uploaded/i4/6000000004395/O1CN015dL7Fj1iKxTvPBQ7Z_!!6000000004395-0-picassoopen.jpg").content))
img2 = Image.open(BytesIO(requests.get(
"http://img.alicdn.com/bao/uploaded/i2/6000000002419/O1CN01peQiCX1Tjwr6pAt1z_!!6000000002419-0-picassoopen.jpg").content))
# 剪裁出右下角
img1 = img1.crop((586, 680, 800, 800))
img2 = img2.crop((586, 680, 800, 800))
# # 尝试调整图片对比度,但测试对识别结果没有帮助
# img1 = img1.convert("L")
# img2 = img2.convert("L")
# 保存
img1.save('D:\\Files\\python\\img_to_str\\img1.jpg')
img2.save('D:\\Files\\python\\img_to_str\\img2.jpg')
# 识别结果输出
print('img1:', pytesseract.image_to_string(img1, lang="chi_sim"))
print('img2:', pytesseract.image_to_string(img2, lang="chi_sim"))
print('完成')
结果是这样的:
49.3只识别出49.
111无法识别出任何数字
所以,如果要提高识别成功率,各位大佬有什么优化建议?谢谢
|