You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何提升Azure Computer Vision图像文本识别准确率?

Azure Computer Vision OCR 准确率优化方案

针对你遇到的OCR识别准确率低于在线演示工具的问题,以下是具体的代码优化和改进方向:

1. 替换为最新的Read API(核心优化)

你当前使用的recognize_printed_text_in_stream属于旧版OCR接口,而Azure在线演示工具采用的是Read API——这是更先进的文本识别模型,支持更高准确率、多语言场景,同时会返回Bounding Boxes,与在线工具的识别逻辑完全对齐。替换为Read API是提升准确率的关键。

修改后的代码示例:

from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
import time

# 创建ComputerVision Client
client = ComputerVisionClient(ENDPOINT, CognitiveServicesCredentials(API_KEY))

image_path = '/Users/Owner/Documents/Bills Stuff/eBay/Images/Document_20240914_0008.jpg'  

# 使用Read API识别图像文本
with open(image_path, "rb") as image_stream:
    read_response = client.read_in_stream(image_stream, raw=True)

# 获取操作ID,用于查询识别结果
read_operation_location = read_response.headers["Operation-Location"]
operation_id = read_operation_location.split("/")[-1]

# 轮询等待识别完成
while True:
    read_result = client.get_read_result(operation_id)
    if read_result.status not in ['notStarted', 'running']:
        break
    time.sleep(1)

# 提取识别到的文本
if read_result.status == OperationStatusCodes.succeeded:
    for page in read_result.analyze_result.read_results:
        for line in page.lines:
            print(f"   Title: {line.text}")
            # 可选:打印Bounding Box坐标,与在线工具一致
            # print(f"   Bounding Box: {line.bounding_box}")

2. 图像预处理优化

在线工具会自动对输入图像做预处理,你可以在本地先对图像做以下处理,进一步提升准确率:

  • 分辨率调整:确保图像分辨率不低于300DPI,过低的分辨率会导致文本模糊
  • 对比度增强:通过OpenCV等工具提高文本与背景的对比度,减少识别干扰
  • 倾斜矫正:如果图像存在倾斜,先进行几何矫正,保证文本水平对齐
  • 噪点去除:使用高斯模糊等滤波算法消除图像中的噪点或划痕

3. 指定识别语言参数

明确指定识别语言为英文(language="en"),避免自动语言检测出现偏差:

read_response = client.read_in_stream(image_stream, language="en", raw=True)

4. 检查图像质量

确认输入图像没有以下问题:

  • 文本区域被遮挡或模糊
  • 存在反光、阴影等干扰因素
  • 文本过小或过于密集

内容的提问来源于stack exchange,提问作者user615525

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 08:32:11