Языки, кроме английского для Tesseract iOS - PullRequest
2 голосов
/ 01 июня 2011

Я пытаюсь использовать открытый исходный код 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

Чего мне не хватает и как с этим обращаться?

1 Ответ

1 голос
/ 08 ноября 2012

Сначала добавьте tessdata в папку с именем вашего проекта / проекта, а затем (ВАЖНО) перейдите к целям / этапам сборки / скопируйте ресурсы комплекта и добавьте папку tessdata как REFERENCE!

, а затем запустите тессеракт какthis:

// 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, поэтому он работает с английским, но нес итальянскими обученными данными ваша папка tessdata не инициализируется должным образом.

...