OCR:没有得到理想的结果 [英] OCR : Not getting desired result

查看:158
本文介绍了OCR:没有得到理想的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个图像。我试图OCR这个图像中的字母。我没有得到字母'9'和'R'的预期结果。首先我裁剪这些字母,& 并执行以下命令。

I have this image . I am trying to OCR the letters in this image. I am not getting desired result for letters '9' and 'R'. First I cropped these letters, & and executing following command.

tesseract 9.png stdout -psm 8
.

它只是返回。

所有其他字母的OCR工作正常但不是这两个字母(但我认为他们的图像质量并不差)。
任何建议/帮助都表示赞赏。

OCR for all other letters are working fine but not for these two letters(though, I think their image quality is not that bad). Any suggestion/help is appreciated.

推荐答案

我自己没有使用tesseract的经验,但复制了角色和根据谷歌的结果,在内部使用tesseract的 https://www.newocr.com/ 中添加了一些背景资料。

I've no experience with tesseract myself, but replicating the character and adding some background works on https://www.newocr.com/ which uses tesseract internally, according to google result.

所以我用它作为输入:

在该网络应用程序上提供正确的结果: 99999999 ,而单个字符不起作用。也许您可以使用tesseract实现来验证这一点,也许它可以帮助您调整孤立的提取字符以使用tesseract。例如尝试将提取的轮廓的多个副本彼此相邻拼接以提高tesseract输出 - 因为您知道将轮廓缝合在一起的频率,如果它识别出经常出现的相同字符,则会知道输出可能是正确的..

which gives the correct result on that web-app: 99999999, while the single character doesn't work. Maybe you can verify this with your tesseract implementation and maybe it helps you to adjust your isolated extracted characters to work with tesseract. e.g. try to stitch multiple duplicates of your extracted contour next to each other to improve tesseract output - since you know how often you stitched the contour next to each other you'll know that the output might be correct if it recognizes the same character that often times..

同样适用于

边框看起来很重要,如果没有足够的边框,它将识别 P 。一般来说,你应该尝试用纯黑色和纯白色替换背景和前景!不确定web-app使用什么样的预处理...

The border looks important, without enough border it will recognize P. In general afaik you should try to replace background and foreground by pure black and pure white! Not sure what kind of preprocessing the web-app uses...

此代码可用于使用C ++和OpenCV重复图像,但不会添加边界。要做到这一点,你会工作非常相似,但有一些额外的步骤,你必须为边框指定一些颜色。

this code can be used to repeat an image with C++ and OpenCV, but it won't add a border around. To do that you would work very similar but with some additional steps and you would have to assign some color to the border.

编辑:我已更新代码使用每个方向4个像素的边框(你可以调整变量)和黑色背景颜色。

I've updated the code to use a border of 4 pixel in each direction (you can adjust the variable) and with black background color.

这段代码非常简单,对于java中的opencv应该非常相似,python等。

This code is very easy and should be very similar for opencv in java, python, etc.

int main(int argc, char * argv[])
{
    //cv::Mat input = cv::imread("../inputData/ocrR.png");

    if(argc != 3)
    {
        std::cout << "usage: .exe filename #Repetitions" << std::endl;
        return 0;
    }

    std::string filename = argv[1];
    int nRepetitions = atoi(argv[2]);

    cv::Mat inputImage = cv::imread(filename);
    if(inputImage.empty())
    {
        std::cout << "image file " << filename << " could not be loaded" << std::endl;
        return 0;
    }

    // you instead should try to extract the background color from the image (e.g. from the image border)
    cv::Scalar backgroundColor(0,0,0);

    // size of the border in each direction
    int border = 4;

    cv::Mat repeatedImage = cv::Mat(inputImage.rows + 2*border, nRepetitions*inputImage.cols + 2*border, inputImage.type() , backgroundColor);

    cv::Rect roi = cv::Rect(border,border,inputImage.cols, inputImage.rows);

    for(int i=0; i<nRepetitions; ++i)
    {
        // copy original image to subimage of repeated image
        inputImage.copyTo(repeatedImage(roi));

        // update roi position
        roi.x += roi.width;
    }

    // now here you could send your repeated image to tesseract library and test whether nRepetitions times a letter was found.

    cv::imwrite("repeatedImage.png", repeatedImage);
    cv::imshow("repeated image" , repeatedImage);
    cv::waitKey(0);
    return 0;
}

给出这个结果:

这篇关于OCR:没有得到理想的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆