OCR识别之easyocr

人工智能 2025-06-03 15:00:08
import easyocr
import cv2
import matplotlib.pyplot as plt
import numpy as np
#OCR识别之easyocr
# 创建 OCR 阅读器,指定语言(中文简体和英文)
reader = easyocr.Reader(['ch_sim', 'en'])

# 读取图像
image = cv2.imread('9.jpg')

# 识别文字
results = reader.readtext(image)

# 显示识别结果
for (bbox, text, prob) in results:
    # 解析边界框
    (top_left, top_right, bottom_right, bottom_left) = bbox
    top_left = (int(top_left[0]), int(top_left[1]))
    top_right = (int(top_right[0]), int(top_right[1]))
    bottom_right = (int(bottom_right[0]), int(bottom_right[1]))
    bottom_left = (int(bottom_left[0]), int(bottom_left[1]))

    # 在图像上绘制边界框和文本
    cv2.rectangle(image, top_left, bottom_right, (0, 255, 0), 2)
    cv2.putText(image, text, (top_left[0], top_left[1] - 10),
                cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1)

    # 打印识别结果和置信度
    print(f"文本: {text}, 置信度: {prob:.2f}")

# 显示结果图像
plt.figure(figsize=(10, 8))
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.axis('off')
plt.show()



...全文
95 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

4

社区成员

发帖
与我相关
我的任务
社区描述
学习交流人工智能相关算法及技术栈
opencv计算机视觉人工智能 技术论坛(原bbs) 广东省·深圳市
社区管理员
  • 亿只小灿灿
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧