【问题标题】:Tesseract OCR German Special CharactersTesseract OCR 德语特殊字符
【发布时间】:2016-04-08 10:07:04
【问题描述】:

iam 使用 tesseract ocr 在 C++ 中读取德语 png 图像,但我遇到了一些特殊字符的问题,例如

ß ä ö ü 等等。

我是否需要训练 tesseract 才能正确阅读此内容或需要做什么?

This is the part of the original image read by tesseract

    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();

更新

SetConsoleOutputCP(1252);//changed to german.
SetConsoleCP(1252);//changed to german
wcout << "ÄÖÜ?ß" << endl;

// Open input image with leptonica library
Pix *image = pixRead("D:\\Images\\Document.png");
api->Init("D:\\TesseractBeispiele\\Tessaractbeispiel\\Tessaractbeispiel\\tessdata", "deu");
api->SetImage(image);
api->SetVariable("save_blob_choices", "T");
api->SetRectangle(1000, 3000, 9000, 9000);
api->Recognize(NULL);

// Get OCR result
wcout << api->GetUTF8Text());

After changing the Code below the Update 硬编码的变音符号将正确显示,但图像中的文本不正确,我需要更改什么?

tesseract 版本是 3.0.2 leptonica 版本是 1.68

【问题讨论】:

    标签: c++ utf-8 console-application tesseract


    【解决方案1】:

    Tesseract 可以识别 Unicode 字符。您的控制台可能尚未配置为显示它们。

    What encoding/code page is cmd.exe using?

    Unicode characters in Windows command line - how?

    【讨论】:

    • 控制台几乎可以肯定没有为 UTF-8 配置。
    • 如何为 utf8 配置控制台?
    【解决方案2】:
    i don't how to detect German the word from the image in windows environment. but i know how to detect German word to Linux environment. following code may get you some idea.
    
    /*
     * word_OCR.cpp
     *
     *  Created on: Jun 23, 2016
     *      Author: root
     */
    
    #include <tesseract/baseapi.h>
    #include <leptonica/allheaders.h>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc ,char **argv)
    {
        Pix *image = pixRead(argv[1]);
    
        if (image == 0) {
            cout << "Cannot load input file!\n";
        }
    
        tesseract::TessBaseAPI tess;
    // insted of the passing "eng" pass "deu".
        if (tess.Init("/usr/share/tesseract/tessdata", "deu")) {
                fprintf(stderr, "Could not initialize tesseract.\n");
                exit(1);
            }
    
        tess.SetImage(image);
        tess.Recognize(0);
    
        tesseract::ResultIterator *ri = tess.GetIterator();
        tesseract::PageIteratorLevel level = tesseract::RIL_WORD;
    
        if(ri!=0)
        {
            do {
                const char *word = ri->GetUTF8Text(level);
    
                cout << word << endl;
    
                delete []word;
    
            } while (ri->Next(level));
    
    
            delete []ri;
        }
    
    }
    one thing you have to take care that pass good resolution image then and then it works fine.
    

    【讨论】:

    • 如果你想要比这更高的精度,那么你可以在 pixeRead() 中传递 OTSU 阈值图像。我现在在 pixRead() 中传递正常图像。通过 OTSU 阈值图像。我为此开发了算法。 .如果有人想要,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 2018-01-19
    • 2014-03-25
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 2013-07-30
    • 2012-04-16
    • 1970-01-01
    相关资源
    最近更新 更多