OCR : Not getting desired result

雨燕双飞 提交于 2020-01-24 01:19:29

问题


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
.

It is just returning "."

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.


回答1:


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.

So I used this as input:

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..

same works for

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...

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.

EDIT: 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.

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

giving this result:




回答2:


I had a tiny bit more success than you... I did a "Connected Components Analysis" to extract the individual letters, then put a border around each extracted letter and appended them all together into a single horizontal line which gave me this:

And if I then run tesseract I get:

VQQTRF


来源:https://stackoverflow.com/questions/34176517/ocr-not-getting-desired-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!