c# - OCR图像预处理

标签 c# c++ image-processing ocr

我一直在使用 OCR 的 Office 文档成像来从图像中获取文本。对于这张图片,

我想知道在将图像输入 OCR 之前提高图像质量所涉及的预处理步骤。到目前为止,我已经尝试过二值化(阈值)、模糊(高斯)、锐化、平均去除和增加图像的亮度和对比度,但 OCR 引擎仍然无法获得准确的文本(可能成功 50%)。

我想知道预处理步骤(按正确顺序)以提高 C# 中的质量。屏幕图像是通过网络摄像头捕获的。谢谢。

最佳答案

我用我的 DIP 库在 C++ 中对你的图像进行了一些处理,结果如下:

picture pic0,pic1;
pic0.load("ocr_green.png");
pic0.pixel_format(_pf_u);       // RGB -> Grayscale <0-765>
pic0.enhance_range();           // remove DC offset and use full dynamic range <0-765>
pic0.normalize(8,false);        // try to normalize ilumination conditions of image (equalize light) based on 8x8 sqares analysis, do not recolor saturated square with avg color
pic0.enhance_range();           // remove DC offset and use full dynamic range <0-765>
pic1=pic0;                      // copy result to pic1
pic0.pixel_format(_pf_rgba);    // Grayscale -> RGBA
int x,y,c,c0,c1;
for (y=0;y<pic1.ys;y++)         // process all H lines
    {
    c0=pic1.p[y][0].dd; c1=c0;  // find min and max intensity in H line
    for (x=0;x<pic1.xs;x++)
        {
        c=pic1.p[y][x].dd;
        if (c0>c) c0=c;
        if (c1<c) c1=c;
        }
    if (c1-c0<700)              // if difference not big enough blacken H line...
     for (x=0;x<pic1.xs;x++) pic1.p[y][x].dd=0;
    else                        // else binarize H line
     for (x=0;x<pic1.xs;x++)
      if (pic1.p[y][x].dd>=155) pic1.p[y][x].dd=765; else pic1.p[y][x].dd=0;
    }
pic1.pixel_format(_pf_rgba);    // Grayscale -> RGBA

example

左边的图像 (pic0) 只是您的图像,已转换为灰度、增强动态范围至最大和均衡照明。

右图 (pic1) 已二值化,但仅适用于像素强度变化足够大的水平线(如我的评论中所述)...其余设置为黑色...

关于c# - OCR图像预处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34108545/

相关文章:

c# - 类 System.Dynamic.DynamicObject .. 为什么不抽象?

c++ - 如何在 C++ 中将当前时间简洁地添加到字符串中?

c++ - VS 2017 使用交叉编译器构建 x64 项目

c++ - Armadillo:高效的 RAM 稀疏批量插入

ruby-on-rails - 调整回形针大小以适合矩形框

c# - 如何调用VSTS编码的Ui脚本到QTP?

c# - SimpleInjector 解除绑定(bind)/重新绑定(bind)

c++ - 带颜色的双边过滤

c# - .NET 与单声道 : different results for conversion from 2^32 as double to int

java - 从我自己的 java 应用程序中运行 ImageJ 宏