Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set absoluteDataPath properly before configuring the engine #410

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions TesseractOCR/G8Tesseract.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ + (void)clearCache
tesseract::TessBaseAPI::ClearPersistentCache();
}


- (instancetype)init {

self = [super init];
if (self != nil) {

Expand All @@ -97,7 +95,6 @@ - (instancetype)init {
_monitor = new ETEXT_DESC();
_monitor->cancel = tesseractCancelCallbackFunction;
_monitor->cancel_this = (__bridge void*)self;

_absoluteDataPath = [NSBundle mainBundle].bundlePath;

setenv("TESSDATA_PREFIX", [_absoluteDataPath stringByAppendingString:@"/"].fileSystemRepresentation, 1);
Expand All @@ -106,15 +103,22 @@ - (instancetype)init {
return self;
}

- (instancetype)initWithLanguage:(NSString*)language
{
- (instancetype)initWithAbsoluteDataPath:(NSString *)absoluteDataPath {
self = [self init];
_absoluteDataPath = absoluteDataPath.copy;
setenv("TESSDATA_PREFIX", [_absoluteDataPath stringByAppendingString:@"/"].fileSystemRepresentation, 1);
return self;
}

- (instancetype)initWithLanguage:(NSString*)language absoluteDataPath:(NSString *)absoluteDataPath
{
self = [self initWithAbsoluteDataPath:absoluteDataPath];
self.language = language.copy;
return self;
}

- (instancetype)initWithLanguage:(NSString *)language engineMode:(G8OCREngineMode)engineMode {
self = [self initWithLanguage:language];
- (instancetype)initWithLanguage:(NSString *)language engineMode:(G8OCREngineMode)engineMode absoluteDataPath:(NSString *)absoluteDataPath {
self = [self initWithLanguage:language absoluteDataPath:absoluteDataPath];
_engineMode = engineMode;
return self;
}
Expand All @@ -130,15 +134,13 @@ - (instancetype)initWithLanguage:(NSString *)language
NSString *cachesPath = cachesPaths.firstObject;

NSString *absoluteDataPath = [cachesPath stringByAppendingPathComponent:cachesRelatedPath].copy;


self = [self initWithLanguage:language engineMode:engineMode];
self = [self initWithLanguage:language engineMode:engineMode absoluteDataPath:absoluteDataPath];

if (configFileNames) {
NSAssert([configFileNames isKindOfClass:[NSArray class]], @"Error! configFileNames should be of type NSArray");
}

_absoluteDataPath = absoluteDataPath.copy;
_configDictionary = configDictionary;
_configFileNames = configFileNames;

Expand All @@ -151,20 +153,17 @@ - (instancetype)initWithLanguage:(NSString *)language
absoluteDataPath:(NSString *)absoluteDataPath
engineMode:(G8OCREngineMode)engineMode {

self = [self initWithLanguage:language engineMode:engineMode];

self = [self initWithLanguage:language engineMode:engineMode absoluteDataPath:absoluteDataPath];

if (self != nil) {

if (absoluteDataPath != nil) {
[self moveTessdataToDirectoryIfNecessary:absoluteDataPath];
}
_absoluteDataPath = absoluteDataPath.copy;

_configDictionary = configDictionary;
_configFileNames = configFileNames;

setenv("TESSDATA_PREFIX", [_absoluteDataPath stringByAppendingString:@"/"].fileSystemRepresentation, 1);

}
return self;
}
Expand Down Expand Up @@ -233,7 +232,7 @@ - (BOOL)resetEngine
_engineMode = G8OCREngineModeTesseractOnly;
[self freeTesseract];
}

return isInitDone;
}

Expand Down