2

Tesseract オープン ソース コードを使用して、iPhone で英語の文字をコンパイルして認識できるかどうかを確認しようとしています。私はそうすることができました。ここで、「ita.traineddata」を tessdata 内に含めて変更しようとしました

tess->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding],    // Path to tessdata-no ending /.
           "eng");                                                  // ISO 639-3 string or NULL.

tess->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding],    // Path to tessdata-no ending /.
           "ita");                                                  // ISO 639-3 string or NULL.

しかし、私はこのエラーが発生します: Error openning data file /var/mobile/Applications/A37DB8B7-2272-4F80-9836-0034CEB56CC5/Documents/tessdata/ita.traineddata

何が欠けていますか?これをどのように処理する必要がありますか?

4

1 に答える 1

1

最初に tessdata をプロジェクト/プロジェクト名フォルダーに追加し、(重要) ターゲット/ビルド フェーズ/バンドル リソースのコピーに移動し、tessdata フォルダーを参照として追加します。

そして、次のようにテッセラクトを初期化します。

// Set up the tessdata path. This is included in the application bundle
// but is copied to the Documents directory on the first run.
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil;

NSString *dataPath = [documentPath stringByAppendingPathComponent:@"tessdata"];
NSFileManager *fileManager = [NSFileManager defaultManager];
// If the expected store doesn't exist, copy the default store.
if (![fileManager fileExistsAtPath:dataPath]) {
    // get the path to the app bundle (with the tessdata dir)
    NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
    NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"];
    if (tessdataPath) {
        [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
    }
}    
setenv("TESSDATA_PREFIX", [[documentPath stringByAppendingString:@"/"] UTF8String], 1);
// init the tesseract engine.
tesseract = new tesseract::TessBaseAPI();    
tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], "ita");

注:Tesseractは、tessdataフォルダー全体を削除すると、デフォルトとして英語で初期化され、eng.traineddataファイルがなくても機能します。そのため、英語では機能しますが、イタリア語のtraineddataでは機能しません。tessdataフォルダーは初期化されていませんちゃんと。

于 2012-11-08T13:25:57.783 に答える