Why can't recognize characters in C++ code?

18 views
Skip to first unread message

易鑫

unread,
Jan 29, 2019, 9:38:52 PM1/29/19
to tesseract-ocr
Hello,everyone:
    I have fine tuned a new lstm model named engtuned.traineddata. I have test it in the command line,it is okay.

In the command line:
PS D:\git_workspace\TableOcrRecognition\Tesserac-OCR-Train> tesseract D:\git_workspace\TableOcrRecognition\TableDetect\TableDetect\Data\Tmp\2.png stdout -l engtuned --psm 7 --oem 3
Warning: Invalid resolution 0 dpi. Using 70 instead.
Q345L90X8

The result is good,but when I used it in C++ code,it can not recognize the characters correctly.Here is my C++ code.

 tesseract::TessBaseAPI *tessApi = new tesseract::TessBaseAPI();
    // --psm 7 --oem 3
    if (tessApi->Init("../../tessdata", "engtuned", tesseract::OcrEngineMode::OEM_DEFAULT)) {
        std::cout << "OCRTesseract: Could not initialize tesseract." << std::endl;
        return EINITTESS;
    }
    // setup
    tessApi->SetPageSegMode(tesseract::PageSegMode::PSM_SINGLE_LINE);
    tessApi->SetVariable("save_best_choices", "T");


    ...

   tessApi->SetImage(binImg.data, binImg.cols, binImg.rows, binImg.step[1], binImg.step[0]);
        
    tessApi->Recognize(0);
    string result = std::unique_ptr<char[]>(tessApi->GetUTF8Text()).get();
    cout << result < <endl;

I do not know where is wrong,can you help? thanks a lot.

易鑫

unread,
Jan 29, 2019, 10:15:25 PM1/29/19
to tesseract-ocr
The problem has been solved.The reason is that the binary image should use white as background and black as foreground,
Maybe there exist some issues during my training process.

易鑫 <yixinl...@gmail.com> 于2019年1月30日周三 上午10:38写道:
--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To post to this group, send email to tesser...@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/3f61f056-9aee-4967-ab13-cfced376f8fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages