OCR:没有得到想要的结果

OCR : Not getting desired result

我有这张图片 . 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, & 并执行以下命令。

tesseract 9.png stdout -psm 8
.

它只是返回“.”

所有其他字母的 OCR 都工作正常,但对这两个字母则不然(尽管我认为它们的图像质量还不错)。 任何 suggestion/help 表示赞赏。

我自己没有使用 tesseract 的经验,但根据 google 结果,复制角色并添加一些背景可以在内部使用 tesseract 的 https://www.newocr.com/ 上工作。

所以我用这个作为输入:

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

同样适用于

边框看起来很重要,没有足够的边框它会识别 P。一般来说 afaik 你应该尝试用纯黑色和纯白色替换背景和前景!不确定网络应用程序使用哪种预处理...

此代码可用于使用 C++ 和 OpenCV 重复图像,但不会在周围添加边框。为此,您的工作将非常相似,但需要一些额外的步骤,并且您必须为边框指定一些颜色。

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

这段代码非常简单,在java、python等opencv中应该非常相似

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;
}

得出这个结果:

我比你成功了一点点...我做了 "Connected Components Analysis" 来提取单个字母,然后在每个提取的字母周围加上边框,然后将它们全部附加到一条水平线上,这给了我这个:

然后如果我 运行 tesseract 我得到:

VQQTRF