# API examples |
#APIの例 |
This wiki provides simple examples on how to use the tesseract-ocr API (v3.02.02-4.0.0) in C++. |
このWikiは、C ++でtesseract-ocr API(v3.02.02-4.0.0)を使用する方法に関する簡単な例を提供します。 |
It is expected that tesseract-ocr is correctly installed including all dependecies. |
tesseract-ocrがすべての依存関係を含めて正しくインストールされていることが期待されます。 |
It is expected the user is familiar with C++, compiling and linking program on their platform, though basic compilation examples are included for beginners with Linux. |
基本的なコンパイル例はLinuxの初心者向けですが(#compiling-c-api-programs-linux)、ユーザーは自分のプラットフォームでC ++、プログラムのコンパイルおよびリンクに精通していることが期待されます。 |
More details about tesseract-ocr API can be found at baseapi.h. |
tesseract-ocr APIについての詳細はbaseapi.hにあります。 |
# Basic example |
#基本的な例 |
Code: |
コード: |
`c++ | `c ++ |
#include |
#include |
#include |
#include |
int main() |
int main() |
{ |
{ |
char *outText; |
char * outText; |
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); |
tesseract :: TessBaseAPI * api = new tesseract :: TessBaseAPI(); |
// Initialize tesseract-ocr with English, without specifying tessdata path |
// tessdataパスを指定せずに、tesseract-ocrを英語で初期化します |
if (api->Init(NULL, "eng")) { |
if(api-> Init(NULL、 "eng")){ |
fprintf(stderr, "Could not initialize tesseract.\n"); |
fprintf(stderr、 "tesseractを初期化できませんでした。\ n"); |
exit(1); |
出口(1); |
} |
} |
// Open input image with leptonica library |
// leptonicaライブラリで入力画像を開く |
Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif"); |
Pix * image = pixRead( "/ usr / src / tesseract / testing / phototest.tif"); |
api->SetImage(image); |
api-> SetImage(image); |
// Get OCR result |
// OCR結果を取得する |
outText = api->GetUTF8Text(); |
outText = api-> GetUTF8Text(); |
printf("OCR output:\n%s", outText); |
printf( "OCR出力:\ n%s"、outText); |
// Destroy used object and release memory |
//使用済みオブジェクトを破棄してメモリを解放する |
api->End(); |
api-> End(); |
delete [] outText; |
delete [] outText; |
pixDestroy(&image); |
pixDestroy(&image); |
return 0; |
0を返します。 |
} |
} |
` | ` |
The program must be linked to the tesseract-ocr and leptonica libraries. |
プログラムはtesseract-ocrおよびleptonicaライブラリーにリンクされていなければなりません。 |
If you want to restrict recognition to a sub-rectangle of the image - call SetRectangle(left, top, width, height) after SetImage. Each SetRectangle clears the recogntion results so multiple rectangles can be recognized with the same image. E.g. |
認識を画像のサブ矩形に制限したい場合は、SetImageの後に_SetRectangle(left、top、width、height)_を呼び出します。各SetRectangleは認識結果を消去するので、同じ画像で複数の長方形を認識することができます。例えば。 |
`c++ | `c ++ |
api->SetRectangle(30, 86, 590, 100); |
api-> SetRectangle(30、86、590、100); |
` | ` |
# GetComponentImages example |
#GetComponentImagesの例 |
`c++ | `c ++ |
Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif"); |
Pix * image = pixRead( "/ usr / src / tesseract / testing / phototest.tif"); |
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); |
tesseract :: TessBaseAPI * api = new tesseract :: TessBaseAPI(); |
api->Init(NULL, "eng"); |
api-> Init(NULL、 "eng"); |
api->SetImage(image); |
api-> SetImage(image); |
Boxa* boxes = api->GetComponentImages(tesseract::RIL_TEXTLINE, true, NULL, NULL); |
Boxa * boxes = api-> GetComponentImages(tesseract :: RIL_TEXTLINE、true、NULL、NULL); |
printf("Found %d textline image components.\n", boxes->n); |
printf( "%dテキスト行の画像コンポーネントが見つかりました。\ n"、boxes-> n); |
for (int i = 0; i < boxes->n; i++) { |
for(int i = 0; i n; i ++){ |
BOX* box = boxaGetBox(boxes, i, L_CLONE); |
BOX * box = boxaGetBox(boxes、i、L_CLONE); |
api->SetRectangle(box->x, box->y, box->w, box->h); |
api-> SetRectangle(ボックス - > x、ボックス - > y、ボックス - > w、ボックス - > h); |
char* ocrResult = api->GetUTF8Text(); |
char * ocrResult = api-> GetUTF8Text(); |
int conf = api->MeanTextConf(); |
int conf = api-> MeanTextConf(); |
fprintf(stdout, "Box[%d]: x=%d, y=%d, w=%d, h=%d, confidence: %d, text: %s", |
fprintf(stdout、 "ボックス[%d]:x =%d、y =%d、w =%d、h =%d、信頼度:%d、テキスト:%s"、、 |
i, box->x, box->y, box->w, box->h, conf, ocrResult); |
i、box-> x、box-> y、box-> w、box-> h、conf、ocrResult); |
} |
} |
` | ` |
# Result iterator example |
#結果イテレータの例 |
It is possible to get confidence value and BoundingBox per word from a ResultIterator: |
ResultIteratorから単語ごとの信頼値とBoundingBoxを取得することが可能です。 |
`c++ | `c ++ |
Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif"); |
Pix * image = pixRead( "/ usr / src / tesseract / testing / phototest.tif"); |
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); |
tesseract :: TessBaseAPI * api = new tesseract :: TessBaseAPI(); |
api->Init(NULL, "eng"); |
api-> Init(NULL、 "eng"); |
api->SetImage(image); |
api-> SetImage(image); |
api->Recognize(0); |
api->認識(0); |
tesseract::ResultIterator* ri = api->GetIterator(); |
tesseract :: ResultIterator * ri = api-> GetIterator(); |
tesseract::PageIteratorLevel level = tesseract::RIL_WORD; |
tesseract :: PageIteratorLevel level = tesseract :: RIL_WORD; |
if (ri != 0) { |
if(ri!= 0){ |
do { |
行う { |
const char* word = ri->GetUTF8Text(level); |
const char * word = ri-> GetUTF8Text(level); |
float conf = ri->Confidence(level); |
float conf = ri->信頼度(レベル)。 |
int x1, y1, x2, y2; |
int x1、y1、x2、y2。 |
ri->BoundingBox(level, &x1, &y1, &x2, &y2); |
ri-> BoundingBox(レベル、&x 1、&y 1、&x 2、&y 2); |
printf("word: '%s'; \tconf: %.2f; BoundingBox: %d,%d,%d,%d;\n", |
printf( "単語: '%s'; \ tconf:%.2f;境界ボックス:%d、%d、%d、%d; \ n"、 |
word, conf, x1, y1, x2, y2); |
ワード、conf、x1、y1、x2、y2)。 |
delete[] word; |
[]単語を削除します。 |
} while (ri->Next(level)); |
while(ri-> Next(level)); |
} |
} |
` | ` |
It is also possible to use other iterator levels (block, line, word, etc.), see PageiteratorLevel. |
他のイテレータレベル(ブロック、行、単語など)を使用することもできます。PageiteratorLevelを参照してください。 #L219) |
# Orientation and script detection (OSD) example |
#オリエンテーションと文字検出(OSD)の例 |
`c++ | `c ++ |
const char* inputfile = "/usr/src/tesseract/testing/eurotext.tif"; |
const char * inputfile = "/usr/src/tesseract/testing/eurotext.tif"; |
tesseract::Orientation orientation; |
tesseract ::オリエンテーション |
tesseract::WritingDirection direction; |
tesseract :: WritingDirectionの方向。 |
tesseract::TextlineOrder order; |
tesseract :: TextlineOrderの順序 |
float deskew_angle; |
float deskew_angle; |
PIX *image = pixRead(inputfile); |
PIX * image = pixRead(入力ファイル); |
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); |
tesseract :: TessBaseAPI * api = new tesseract :: TessBaseAPI(); |
api->Init("/usr/src/tesseract/", "eng"); |
api-> Init( "/ usr / src / tesseract /"、 "eng"); |
api->SetPageSegMode(tesseract::PSM_AUTO_OSD); |
SetPageSegMode(tesseract :: PSM_AUTO_OSD); |
api->SetImage(image); |
api-> SetImage(image); |
api->Recognize(0); |
api->認識(0); |
tesseract::PageIterator* it = api->AnalyseLayout(); |
tesseract :: PageIterator * it = api-> AnalyseLayout(); |
it->Orientation(&orientation, &direction, &order, &deskew_angle); |
it-> Orientation(&orientation、&direction、&order、&deskew_angle); |
printf("Orientation: %d;\nWritingDirection: %d\nTextlineOrder: %d\n" \ |
printf( "印刷の向き:%d; \ n書き込み方向:%d \ nテキスト行の順序:%d \ n" \ |
"Deskew angle: %.4f\n", |
"傾き角:%.4f \ n"、 |
orientation, direction, order, deskew_angle); |
方向、方向、順序、deskew_angle); |
` | ` |
Explanation for result codes are in publictypes.h |
結果コードの説明は[publictypes.h]にあります(https://github.com/tesseract-ocr/tesseract/blob/master/src/ccstruct/publictypes.h#L120) |
# Example of iterator over the classifier choices for a single symbol |
#単一のシンボルに対する分類子の選択に対する反復子の例 |
`c++ | `c ++ |
Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif"); |
Pix * image = pixRead( "/ usr / src / tesseract / testing / phototest.tif"); |
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); |
tesseract :: TessBaseAPI * api = new tesseract :: TessBaseAPI(); |
api->Init(NULL, "eng"); |
api-> Init(NULL、 "eng"); |
api->SetImage(image); |
api-> SetImage(image); |
api->SetVariable("save_blob_choices", "T"); |
api-> SetVariable( "save_blob_choices"、 "T"); |
api->SetRectangle(37, 228, 548, 31); |
api-> SetRectangle(37、228、548、31); |
api->Recognize(NULL); |
認識(NULL); |
tesseract::ResultIterator* ri = api->GetIterator(); |
tesseract :: ResultIterator * ri = api-> GetIterator(); |
tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL; |
tesseract :: PageIteratorLevel level = tesseract :: RIL_SYMBOL; |
if(ri != 0) { |
if(ri!= 0){ |
do { |
行う { |
const char* symbol = ri->GetUTF8Text(level); |
const char * symbol = ri-> GetUTF8Text(level); |
float conf = ri->Confidence(level); |
float conf = ri->信頼度(レベル)。 |
if(symbol != 0) { |
if(symbol!= 0){ |
printf("symbol %s, conf: %f", symbol, conf); |
printf( "シンボル%s、conf:%f"、シンボル、conf); |
bool indent = false; |
bool indent = false; |
tesseract::ChoiceIterator ci(*ri); |
tesseract :: ChoiceIterator ci(* ri); |
do { |
行う { |
if (indent) printf("\t\t "); |
printf( "\ t \ t");の場合(インデント) |
printf("\t- "); |
printf( "\ t-"); |
const char* choice = ci.GetUTF8Text(); |
const char * choice = ci.GetUTF8Text(); |
printf("%s conf: %f\n", choice, ci.Confidence()); |
printf( "%s conf:%f \ n"、選択、ci.Confidence()); |
indent = true; |
indent = true; |
} while(ci.Next()); |
while(ci.Next()); |
} |
} |
printf("---------------------------------------------\n"); |
printf( "--------------------------------------------- \ n "); |
delete[] symbol; |
[]記号を削除します。 |
} while((ri->Next(level))); |
while((ri-> Next(level))); |
} |
} |
` | ` |
# Compiling C++ API programs on Linux |
#LinuxでC ++ APIプログラムをコンパイルする |
Including and linking to Tesseract's API is done in a standard Linux way. To compile a basic program against the API, you can use a command like this: |
TesseractのAPIの組み込みとリンクは、標準のLinuxの方法で行われます。 APIに対して基本プログラムをコンパイルするには、次のようなコマンドを使用できます。 |
` | ` |
g++ -o myprogram myprogram.cpp -llept -ltesseract |
g ++ -o myprogram myprogram.cpp -llept-ltesseract |
` | ` |
If Tesseract is installed in an unusual place, you can specify the include and lib directories explicitly with g++'s -I and -L flags, like this: |
Tesseractが異常な場所にインストールされている場合は、次のようにg ++の-Iおよび-Lフラグを使用してincludeおよびlibディレクトリを明示的に指定できます。 |
` | ` |
g++ -o myprogram myprogram.cpp -I/home/nick/local/include/tesseract -L/home/nick/local/lib -llept -ltesseract |
g ++ -o myprogram myprogram.cpp -I / home / nick / local / include / tesseract -L / home / nick /ローカル/ lib -llept -ltesseract |
` | ` |
# C-API in python |
#PythonのC-API |
Tesseract-ocr from version 3.02.02 provide C-API. This enable to use tesseract-ocr shared library in python (and other languages that can use C libraries): |
バージョン3.02.02からのTesseract-ocrはC-APIを提供します。これはpythonでtesseract-ocr共有ライブラリを使う(そしてC言語を使うことができる他の言語)を可能にします。ライブラリ): |
```python |
python |
import os |
輸入os |
import ctypes |
ctypeをインポート |
lang = "eng" |
lang = "eng" |
filename = "/usr/src/tesseract-ocr/phototest.tif" |
filename = "/usr/src/tesseract-ocr/phototest.tif" |
libname = "/usr/local/lib64/libtesseract.so.3" |
libname = "/usr/local/lib64/libtesseract.so.3" |
TESSDATA_PREFIX = os.environ.get('TESSDATA_PREFIX') |
TESSDATA_PREFIX = os.environ.get( 'TESSDATA_PREFIX') |
if not TESSDATA_PREFIX: |
TESSDATA_PREFIXでない場合 |
TESSDATA_PREFIX = "../" |
TESSDATA_PREFIX = "../" |
tesseract = ctypes.cdll.LoadLibrary(libname) |
tesseract = ctypes.cdll.LoadLibrary(libname) |
tesseract.TessVersion.restype = ctypes.c_char_p |
tesseract.TessVersion.restype = ctypes.c_char_p |
tesseract_version = tesseract.TessVersion() |
tesseract_version = tesseract.TessVersion() |
api = tesseract.TessBaseAPICreate() |
api = tesseract.TessBaseAPICreate() |
rc = tesseract.TessBaseAPIInit3(api, TESSDATA_PREFIX, lang) |
rc = tesseract.TessBaseAPIInit3(api、TESSDATA_PREFIX、lang) |
if (rc): |
if(rc): |
tesseract.TessBaseAPIDelete(api) |
tesseract.TessBaseAPIDelete(api) |
print("Could not initialize tesseract.\n") |
print( "tesseractを初期化できませんでした。\ n") |
exit(3) |
出口(3) |
text_out = tesseract.TessBaseAPIProcessPages(api, filename, None, 0) |
text_out = tesseract.TessBaseAPIProcessPages(api、filename、None、0) |
result_text = ctypes.string_at(text_out) |
result_text = ctypes.string_at(text_out) |
print 'Tesseract-ocr version', tesseract_version |
「Tesseract-ocrバージョン」、tesseract_versionを印刷します。 |
print result_text |
result_textを印刷する |
` | ` |
Example of passing python file object to C-API can be found at pastebin. |
PythonファイルオブジェクトをC-APIに渡す例はpastebinにあります。 |
Example of extracting orientation from Tesseract 4.0: |
Tesseract 4.0から方向を抽出する例: |
```python |
python |
# /usr/bin/env python3 |
#/ usr / bin / env python3 |
# coding: utf-8 |
#コーディング:utf-8 |
PATH_TO_LIBTESS = '/path/to/development/libtesseract.so' |
PATH_TO_LIBTESS = '/path/to/development/libtesseract.so' |
import cffi # requires "pip install cffi" |
import cffi#には "pip install cffi"が必要です。 |
ffi = cffi.FFI() |
ffi = cffi.FFI() |
ffi.cdef(""" |
ffi.cdef( "" " |
struct Pix; |
Pixを構築します。 |
typedef struct Pix PIX; |
type PIX PIX PIXを構築します。 |
PIX pixRead ( const char filename ); |
PIX pixRead(const char filename); |
char * getLeptonicaVersion ( ); |
char * getLeptonicaVersion(); |
typedef struct TessBaseAPI TessBaseAPI; |
typedef struct TessBaseAPI TessBaseAPI; |
typedef int BOOL; |
typedef int BOOL; |
const char* TessVersion(); |
const char * TessVersion(); |
TessBaseAPI* TessBaseAPICreate(); |
TessBaseAPI * TessBaseAPICreate(); |
int TessBaseAPIInit3(TessBaseAPI handle, const char datapath, const char* language); |
int TessBaseAPIInit3(TessBaseAPI ハンドル、const char データパス、const char *言語); |
void TessBaseAPISetImage2(TessBaseAPI handle, struct Pix pix); |
void TessBaseAPISetImage2(TessBaseAPI ハンドル、Pix pix構造体); |
BOOL TessBaseAPIDetectOrientationScript(TessBaseAPI* handle, char** best_script_name, |
BOOL TessBaseAPIDetectOrientationScript(TessBaseAPI *ハンドル、char ** best_script_name、 |
int best_orientation_deg, float script_confidence, |
int best_orientation_deg、float script_confidence、 |
float* orientation_confidence); |
float * orientation_confidence); |
""") |
"" ") |
libtess = ffi.dlopen(PATH_TO_LIBTESS) |
libtess = ffi.dlopen(PATH_TO_LIBTESS) |
from ctypes.util import find_library |
ctypes.util import find_libraryから |
liblept = ffi.dlopen(find_library('lept')) |
liblept = ffi.dlopen(find_library( 'lept')) |
ffi.string(libtess.TessVersion()) |
ffi.string(libtess.TessVersion()) |
ffi.string(liblept.getLeptonicaVersion()) |
ffi.string(liblept.getLeptonicaVersion()) |
api = libtess.TessBaseAPICreate() |
api = libtess.TessBaseAPICreate() |
libtess.TessBaseAPIInit3(api, ffi.NULL, ffi.NULL) |
libtess.TessBaseAPIInit3(api、ffi.NULL、ffi.NULL) |
pix = liblept.pixRead('mono.png'.encode()) |
pix = liblept.pixRead( 'mono.png'.encode()) |
libtess.TessBaseAPISetImage2(api, pix) |
libtess.TessBaseAPISetImage2(api、pix) |
script_name = ffi.new('char **') |
script_name = ffi.new( 'char **') |
orient_deg = ffi.new('int *') |
orient_deg = ffi.new( 'int *') |
script_conf = ffi.new('float *') |
script_conf = ffi.new( 'float *') |
orient_conf = ffi.new('float *') |
orient_conf = ffi.new( 'float *') |
libtess.TessBaseAPIDetectOrientationScript(api, script_name, orient_deg, script_conf, orient_conf) |
libtess.TessBaseAPIDetectOrientationScript(api、script_name、orient_deg、script_conf、orient_conf) |
print(ffi.string(script_name).decode('utf-8')) |
print(ffi.string(script_name).decode( 'utf-8')) |
print(orient_deg[0]) |
print(orient_deg [0]) |
print(script_conf[0]) |
print(script_conf [0]) |
print(orient_conf[0]) |
print(orient_conf [0]) |
` | ` |
# Example using the C-API in a C program |
#CプログラムでC-APIを使用する例 |
The C-API can of course also be used by regular C programs, as in this very basic example. |
この非常に基本的な例のように、C-APIは通常のCプログラムでももちろん使用できます。 |
`c | `c |
#include |
#include |
#include |
#include |
#include |
#include |
void die(const char *errstr) { |
void die(const char * errstr){ |
fputs(errstr, stderr); |
exit(1); |
} |
} |
int main(int argc, char *argv[]) { |
int main(int argc、char * argv []){ |
TessBaseAPI *handle; |
PIX *img; |
char *text; |
if((img = pixRead("img.png")) == NULL) |
handle = TessBaseAPICreate(); |
if(TessBaseAPIInit3(handle, NULL, "eng") != 0) |
TessBaseAPISetImage2(handle, img); |
if(TessBaseAPIRecognize(handle, NULL) != 0) |
if((text = TessBaseAPIGetUTF8Text(handle)) == NULL) |
fputs(text, stdout); |
TessDeleteText(text); |
TessBaseAPIEnd(handle); |
TessBaseAPIDelete(handle); |
pixDestroy(&img); |
return 0; |
} |
} |
` | ` |
On Linux you can compile it as you would build a program using the C++ API. |
Linuxでは[C ++ APIを使ってプログラムをビルドするのと同じようにコンパイルする]ことができます(#compiling-c-api-programs-linux)。 |
# Example creating searchable pdf from image in C++ |
#C ++で画像から検索可能なPDFを作成する例 |
`c++ | `c ++ |
#include |
#include |
#include |
#include |
#include |
#include |
int main() |
int main() |
{ |
{ |
const char* input_image = "/usr/src/tesseract-oc/testing/phototest.tif"; |
const char * input_image = "/usr/src/tesseract-oc/testing/phototest.tif"; |
const char* output_base = "my_first_tesseract_pdf"; |
const char * output_base = "my_first_tesseract_pdf"; |
const char* datapath = "/Projects/OCR/tesseract/tessdata"; |
const char * datapath = "/プロジェクト/ OCR / tesseract / tessdata"; |
int timeout_ms = 5000; |
int timeout_ms = 5000; |
const char* retry_config = nullptr; |
const char * retry_config = nullptr; |
bool textonly = false; |
bool textonly = false; |
int jpg_quality = 92; |
int jpg_quality = 92; |
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); |
tesseract :: TessBaseAPI * api = new tesseract :: TessBaseAPI(); |
if (api->Init(datapath, "eng")) { |
if(api-> Init(datapath、 "eng")){ |
fprintf(stderr, "Could not initialize tesseract.\n"); |
fprintf(stderr、 "tesseractを初期化できませんでした。\ n"); |
exit(1); |
出口(1); |
} |
} |
tesseract::TessPDFRenderer *renderer = new tesseract::TessPDFRenderer( |
tesseract :: TessPDFRenderer * renderer = new tesseract :: TessPDFRenderer( |
output_base, api->GetDatapath(), textonly, jpg_quality); |
output_base、api-> GetDatapath()、textonly、jpg_quality); |
bool succeed = api->ProcessPages(input_image, retry_config, timeout_ms, renderer); |
bool succeed = api-> ProcessPages(input_image、retry_config、timeout_ms、renderer); |
if (!succeed) { |
if(!成功){ |
fprintf(stderr, "Error during processing.\n"); |
fprintf(stderr、 "処理中にエラーが発生しました。\ n"); |
return EXIT_FAILURE; |
EXIT_FAILUREを返します。 |
} |
} |
api->End(); |
api-> End(); |
return EXIT_SUCCESS; |
EXIT_SUCCESSを返します。 |
} |
} |
` | ` |
# Example of monitoring OCR progress in C++ |
#C ++でOCRの進捗を監視する例 |
`c++ | `c ++ |
#include |
#include |
#include |
#include |
#include |
#include |
#include |
#include |
void monitorProgress(ETEXT_DESC *monitor, int page); |
void monitorProgress(ETEXT_DESC * monitor、int page); |
void ocrProcess(tesseract::TessBaseAPI api, ETEXT_DESC monitor); |
void ocrProcess(tesseract :: TessBaseAPI api、ETEXT_DESC monitor); |
void monitorProgress(ETEXT_DESC *monitor, int page) { |
void monitorProgress(ETEXT_DESC *モニタ、intページ){ |
while (1) { |
while(1){ |
printf( "\r%3d%%", monitor[page].progress); |
printf( "\ r%3d %%"、モニター[ページ] .progress); |
fflush (stdout); |
fflush(標準出力)。 |
if (monitor[page].progress==100) |
if(monitor [page] .progress == 100) |
break; |
ブレーク; |
} |
} |
} |
} |
void ocrProcess(tesseract::TessBaseAPI api, ETEXT_DESC monitor) { |
void ocrProcess(tesseract :: TessBaseAPI api、ETEXT_DESC monitor){ |
api->Recognize(monitor); |
認識 - 監視(監視) |
} |
} |
int main() { |
int main(){ |
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); |
tesseract :: TessBaseAPI * api = new tesseract :: TessBaseAPI(); |
ETEXT_DESC *monitor = new ETEXT_DESC(); |
ETEXT_DESC * monitor = new ETEXT_DESC(); |
if (api->Init("/tesseract/tessdata_best", "eng")) { |
if(api-> Init( "/ tesseract / tessdata_best"、 "eng")){ |
fprintf(stderr, "Could not initialize tesseract.\n"); |
fprintf(stderr、 "tesseractを初期化できませんでした。\ n"); |
return 1; |
1を返します。 |
} |
} |
api->SetPageSegMode(tesseract::PSM_AUTO); |
SetPageSegMode(tesseract :: PSM_AUTO); |
Pix *image = pixRead("/tesseract-ocr/test/testing/phototest.tif"); |
Pix * image = pixRead( "/ tesseract-ocr / test / testing / phototest.tif"); |
if (!image) { |
if(!image){ |
fprintf(stderr, "Leptonica can't process input file!\n"); |
fprintf(stderr、 "Leptonicaは入力ファイルを処理できません!\ n"); |
return 2; |
2を返します。 |
} |
} |
api->SetImage(image); |
api-> SetImage(image); |
int page = 0; |
int page = 0; |
std::thread t1(ocrProcess, api, monitor); |
std :: thread t1(ocrProcess、api、monitor); |
std::thread t2(monitorProgress, monitor, page); |
std :: thread t2(monitorProgress、monitor、page); |
t1.join(); |
t1.join(); |
t2.join(); |
t2.join(); |
pixDestroy(&image); |
pixDestroy(&image); |
char *outText = api->GetUTF8Text(); |
char * outText = api-> GetUTF8Text(); |
printf("\n%s", outText); |
printf( "\ n%s"、outText); |
if (outText) |
if(outText) |
delete [] outText; |
delete [] outText; |
api->End(); |
api-> End(); |
return 0; |
0を返します。 |
} |
} |
` | ` |
More complex example (e.g. cancelling OCR process) can be found in source code of TesseractGui, gimagereader or android textfairy app. |
より複雑な例(OCRプロセスのキャンセルなど)は、TesseractGuiのソースコードにあります。[gimagereader](https:// fossies) .org / linux / gimagereader / qt / src / Recognizer.cc)またはandroid textfairy app。 |