由于字体细节,OCR失败

时间:2012-03-30 15:26:56

标签: c# image winforms comparison ocr

我有一个包含所有字体字符的库(在我的例子中是Arial)。例如:

enter image description here

我正在使用此库从图像中删除OCR文本。

问题是当你尝试OCR这样的字符“j”,“/”,“t”时 - 字符可能会相互重叠!所以OCR现在是不可能的,因为字符没有匹配模式图像(最多3个像素不同)。

enter image description here

我该如何处理这个问题?有没有更好的方法来比较图像? (C#,WinForms应用程序)

我正在使用此方法进行比较:

unsafe public static bool CompareMemCmp(Bitmap b1, Bitmap b2)
    {
        if ((b1 == null) != (b2 == null)) return false;
        if (b1.Size != b2.Size) return false;

        var bd1 = b1.LockBits(new Rectangle(new System.Drawing.Point(0, 0), b1.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
        var bd2 = b2.LockBits(new Rectangle(new System.Drawing.Point(0, 0), b2.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

        try
        {
            IntPtr bd1scan0 = bd1.Scan0;
            IntPtr bd2scan0 = bd2.Scan0;

            int stride = bd1.Stride;
            int len = stride * b1.Height;

            return memcmp(bd1scan0, bd2scan0, len) == 0;
        }
        finally
        {
            b1.UnlockBits(bd1);
            b2.UnlockBits(bd2);
        }
    }

这是非常快速和可靠..但如果满足上述条件,你就无法得到结果..不幸的是。

2 个答案:

答案 0 :(得分:1)

您可以为每个角色返回一个分数。角色是被描绘的角色的概率。

如果中心像素与边缘像素匹配,则可以使分数更高,这样您就可以更好地进行猜测。

答案 1 :(得分:1)

你可以制作这些角色对(尽管它们可能有不合理的数量......)“角色”即。 “-j”组合将被识别为“-j”字符..

相关问题