Question

I am using the following method to add the tesseract trained data in my project

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // 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], "eng");
    }
    return self;
}

getting the following error

Error opening data file /Users/frf/Library/Application Support/
iPhone Simulator/6.1/Applications/686F83C8-526C-47FB-9F02-
E44FBE69F60B/Documents/tessdata/eng.traineddata

tessdata is not being copied in document directory . what shall i do ?

please suggest edit my above code ...

Was it helpful?

Solution

I assume that the tessdata directory doesn't exist. in user/documents directory.

OTHER TIPS

this piece of code worked for me...

if (tessdataPath) {

                [[NSFileManager defaultManager] createDirectoryAtPath:[documentPath stringByAppendingPathComponent:@"/tessdata"] withIntermediateDirectories:YES attributes:nil error:nil];
                [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
            }

thank you all....@Volker @Vaisakh

Its because your document folder does not contain language file. You have to save language file which added in bundle to document folder.Save that before you initiate tesseract Tesseract* tesseract = [[Tesseract alloc] initWithDataPath:@"tessdata" language:@"eng"]; Please refer the answer here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top