Skip to content

Commit 0cf5a0a

Browse files
author
Patrick Nollet
committed
Add the possibility to copy the files from the application bundle when using the new initializer
Update documentation
1 parent 7d7aefb commit 0cf5a0a

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

TesseractOCR/G8Tesseract.h

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -302,30 +302,37 @@ extern NSInteger const kG8MaxCredibleResolution;
302302
/**
303303
* Initialize Tesseract with the provided language and engine mode.
304304
*
305-
* @param language The language to use in recognition. See
306-
* `language`.
307-
* @param configDictionary A dictionary of config variables to set.
308-
* @param configFileNames An array of file names containing key-value
309-
* config pairs. Config settings can be set at
310-
* initialization or run-time. Furthermore, they
311-
* could be specified at the same time, in which
312-
* case Tesseract will get variables from every
313-
* config file as well as the dictionary.
314-
* The config files must exist in one of two
315-
* possible folders: tessdata/tessconfigs or
316-
* tessdata/configs.
317-
* @param absoluteDataPath If the absoluteDataPath is specified, Tesseract
318-
* will be set to use that path.
319-
* @param engineMode The engine mode to use in recognition. See
320-
* `engineMode`.
305+
* @param language The language to use in recognition. See
306+
* `language`.
307+
* @param configDictionary A dictionary of config variables to set.
308+
* @param configFileNames An array of file names containing key-value
309+
* config pairs. Config settings can be set at
310+
* initialization or run-time. Furthermore, they
311+
* could be specified at the same time, in which
312+
* case Tesseract will get variables from every
313+
* config file as well as the dictionary.
314+
* The config files must exist in one of two
315+
* possible folders: tessdata/tessconfigs or
316+
* tessdata/configs.
317+
* @param absoluteDataPath If the absoluteDataPath is specified, Tesseract
318+
* will be set to use that path. If nil, the
319+
* application bundle will be use instead
320+
* @param engineMode The engine mode to use in recognition. See
321+
* `engineMode`.
322+
* @param copyFilesFromResources Flag to determine if Tesseract should copy the
323+
* whole contents of the tessdata folder in the
324+
* application bundle to the
325+
* absoluteDataPath/tessdata directory
326+
*
321327
*
322328
* @return The initialized Tesseract object, or `nil` if there was an error.
323329
*/
324330
- (id)initWithLanguage:(NSString *)language
325331
configDictionary:(NSDictionary *)configDictionary
326332
configFileNames:(NSArray *)configFileNames
327333
absoluteDataPath:(NSString *)absoluteDataPath
328-
engineMode:(G8OCREngineMode)engineMode NS_DESIGNATED_INITIALIZER;
334+
engineMode:(G8OCREngineMode)engineMode
335+
copyFilesFromResources:(BOOL)copyFilesFromResources NS_DESIGNATED_INITIALIZER;
329336

330337
/**
331338
* Set a Tesseract variable. See G8TesseractParameters.h for the available

TesseractOCR/G8Tesseract.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,23 @@ - (id)initWithLanguage:(NSString *)language
107107
configDictionary:configDictionary
108108
configFileNames:configFileNames
109109
absoluteDataPath:absoluteDataPath
110-
engineMode:engineMode];
110+
engineMode:engineMode
111+
copyFilesFromResources:cachesRelatedPath != nil];
111112
}
112113

113114
- (id)initWithLanguage:(NSString *)language
114115
configDictionary:(NSDictionary *)configDictionary
115116
configFileNames:(NSArray *)configFileNames
116117
absoluteDataPath:(NSString *)absoluteDataPath
117118
engineMode:(G8OCREngineMode)engineMode
119+
copyFilesFromResources:(BOOL)copyFilesFromResources
118120
{
119121
self = [super init];
120122
if (self != nil) {
121123
if (configFileNames) {
122124
NSAssert([configFileNames isKindOfClass:[NSArray class]], @"Error! configFileNames should be of type NSArray");
123125
}
124-
if (absoluteDataPath) {
126+
if (copyFilesFromResources && absoluteDataPath != nil) {
125127
BOOL moveDataSuccess = [self moveTessdataToDirectoryIfNecessary:absoluteDataPath];
126128
if (moveDataSuccess == NO) {
127129
return nil;

0 commit comments

Comments
 (0)