LoginSignup
5
5

More than 3 years have passed since last update.

Tesseract OCR の使い方 (c++)

Last updated at Posted at 2019-06-08

次と同じことを c++ で行いました。
Tesseract OCR の使い方

次のページの Basic example を改造しました。
API examples

プログラム

example01.cpp
// ----------------------------------------------------------------
/*
        example01.cpp

                                                Jun/08/2019
*/
// ----------------------------------------------------------------
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>

int main()
{
    char *outText;

    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
    if (api->Init(NULL, "jpn")) {
        fprintf(stderr, "Could not initialize tesseract.\n");
        exit(1);
    }

    Pix *image = pixRead("hensel_gretel.png");
    api->SetImage(image);
    // Get OCR result
    outText = api->GetUTF8Text();
    printf("OCR output:\n%s", outText);

    // Destroy used object and release memory
    api->End();
    delete [] outText;
    pixDestroy(&image);

    return 0;
}

// ----------------------------------------------------------------
Makefile
example01: example01.cpp
        clang++ -o example01  example01.cpp -ltesseract -llept
clean:
        rm -f example01

コンパイルして実行

$ ./example01 
Warning: Invalid resolution 0 dpi. Using 70 instead.
OCR output:
大 き な 思 の す ぐ 近 く に 、 本 と り か お か み さ ん と 侑
た ち と 一 細 に ほ ん で い ま し た 。 畑 の チ は ヘ ン ゼ ル で な
の 子 は ダ レ ー テ ル と い う 名 前 で し た 、 本 こ り に は ほ 
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5