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

使用IronOcr识别整图与局部区域结果不一致的问题排查

IronOcr 裁剪区域识别无结果问题排查

你在使用IronOcr定位文本位置后,用该区域二次识别同一张图像却无法得到预期文本,可能的原因及解决方法如下:

问题复现代码

var _recognizerIron = new IronTesseract();           
const string file = "assets/sample.jpg";
using var input = new OcrInput(file);
var result = _recognizerIron.Read(input);

var foundWord = result.Words.First(w => w.Text=="7210");
// foundWord.Location: {X = 511 Y = 793 Width = 67 Height = 22}

using var input2 = new OcrInput();
input2.AddImage(file, new CropRectangle(foundWord.Location));
var result2 = _recognizerIron.Read(input2);

Console.Write(result2.Text);
//Expected Result: result2.Text=="7210"
//Actual Result: result2.Text==""

可能的原因与解决方法

  • 裁剪区域边缘切断文字:Tesseract对文字边缘完整性要求较高,若裁剪区域刚好卡着文字边缘,会导致无法识别。解决方法是给裁剪区域增加边距:

    // 给原区域上下左右各扩展5像素
    var expandedRect = new CropRectangle(
        foundWord.Location.X - 5,
        foundWord.Location.Y - 5,
        foundWord.Location.Width + 10,
        foundWord.Location.Height + 10
    );
    input2.AddImage(file, expandedRect);
    
  • 裁剪区域坐标不匹配:先验证裁剪后的图像是否正确包含目标文字,可通过保存裁剪结果确认:

    input2.AddImage(file, foundWord.Location);
    input2.SaveCrop(@"crop_preview.jpg"); // 保存裁剪后的图像到本地
    

    打开crop_preview.jpg检查是否能看到"7210"。如果图像为空或未包含文字,说明第一次识别的坐标是经过预处理后的图像坐标,而非原始图像坐标。

  • 两次识别的预处理配置不一致:IronOcr默认可能对图像做自动预处理(如缩放、降噪),导致第一次识别的坐标与原始图像不匹配。可显式配置统一规则,确保两次识别逻辑一致:

    var config = new OcrConfiguration
    {
        AutoScale = false,
        EnhanceResolution = false
    };
    var _recognizerIron = new IronTesseract(config);
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 13:20:15