2016-04-08 85 views
0

IAM使用的Tesseract OCR在C++讀書德國PNG圖像和我買了一些特殊字符的問題,像正方體OCR德國特殊字符

SS A○ü等。

我需要培訓tesseract閱讀此正確或需要做什麼?

This is the part of the original image read by tesseract

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

UPDATE

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 硬編碼的變音符號會顯示正確,但是從圖像issnt文字正確的,我需要改變什麼?

正方體的版本是3.0.2 leptonica版本是1.68

回答

0
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. 
+1

如果你想要比這更精確,那麼你可以通過pixeRead()中的OTSU閾值圖像。我正在pixRead()中傳遞正常圖像。通過OTSU閾值圖像。我爲此開發了算法。 。讓我知道是否有人想要。 –