Skip to content

Commit 1852071

Browse files
committed
Merge pull request #113 from ws233/master
Added ability to init with config dictionary/files and use Caches directory for "tessdata" folder location.
2 parents 48b3dbd + 29cb747 commit 1852071

File tree

21 files changed

+508288
-52
lines changed

21 files changed

+508288
-52
lines changed

Products/TesseractOCR.framework/Versions/A/Headers/G8Tesseract.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
*/
4141
@property (nonatomic, copy) NSString* language;
4242

43+
/**
44+
* The path to the tessdata file, if it was specified in a call to initWithLanguage:configDictionary:configFileNames:cachesRelatedDataPath:engineMode: as a cachesRelatedDataPath
45+
* Otherwise it's supposed that the tessdata folder is located in the application bundle
46+
*/
47+
@property (nonatomic, readonly, copy) NSString *absoluteDataPath;
48+
4349
/**
4450
* The recognition mode to use. See `G8OCREngineMode` in G8Constants.h for the
4551
* available recognition modes.
@@ -228,6 +234,30 @@
228234
- (id)initWithLanguage:(NSString*)language
229235
engineMode:(G8OCREngineMode)engineMode;
230236

237+
/**
238+
* Initialize Tesseract with the provided language and engine mode.
239+
*
240+
* @param language The language to use in recognition. See `language`.
241+
* @param configDictionary A dictioanry of the config variables
242+
* @param configFileNames An array of file names containing key-value config pairs. All the config
243+
* variables can be init only and debug time both. Furthermore they could be
244+
* specified at the same time, in such case tesseract will get variables from
245+
* every file and dictionary all together.
246+
* The files are searched into two folders, which are tessdata/tessconfigs and tessdata/configs
247+
* @param cachesRelatedPath If the cachesRelatedDataPath is specified, the whole content of the tessdata from the
248+
* application bundle is copied to the Library/Caches/cachesRelatedDataPath/tessdata
249+
* and tesseract is initialized with that path.
250+
* @param engineMode The engine mode to use in recognition. See `engineMode`.
251+
*
252+
* @return The initialized Tesseract object, or `nil` if there was an error.
253+
*/
254+
255+
- (id)initWithLanguage:(NSString *)language
256+
configDictionary:(NSDictionary *)configDictionary
257+
configFileNames:(NSArray *)configFileNames
258+
cachesRelatedDataPath:(NSString *)cachesRelatedDataPath
259+
engineMode:(G8OCREngineMode)engineMode NS_DESIGNATED_INITIALIZER;
260+
231261
/**
232262
* Set a Tesseract variable. See G8TesseractParameters.h for the available
233263
* options.
@@ -237,6 +267,16 @@
237267
*/
238268
- (void)setVariableValue:(NSString *)value forKey:(NSString *)key;
239269

270+
/**
271+
* Returns a Tesseract variable for the given key. See G8TesseractParameters.h for the available
272+
* options.
273+
*
274+
* @param key The option to get.
275+
*
276+
* @return returns the variable value for the given key, if it's beeb set. nil otherwise.
277+
*/
278+
- (NSString*)variableValueForKey:(NSString *)key;
279+
240280
/**
241281
* Set Tesseract variables using a dictionary. See G8TesseractParameters.h for
242282
* the available options.
39.4 KB
Binary file not shown.

Template Framework Project/Template Framework Project.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
64DDA74E188FD7D10025590D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6400DDEA180C5DE000443362 /* Main.storyboard */; };
2222
64DDA75B188FD9140025590D /* tessdata in Resources */ = {isa = PBXBuildFile; fileRef = 64DDA75A188FD9140025590D /* tessdata */; };
2323
64E40AB1180C6D4D00C36DDE /* libstdc++.6.0.9.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 64E40AB0180C6D4D00C36DDE /* libstdc++.6.0.9.dylib */; };
24+
736EFF261A5877200031B432 /* tessdata-rus in Resources */ = {isa = PBXBuildFile; fileRef = 736EFF251A5877200031B432 /* tessdata-rus */; };
2425
/* End PBXBuildFile section */
2526

2627
/* Begin PBXFileReference section */
@@ -43,6 +44,7 @@
4344
6490748F198A5CD500D728CC /* CoreImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreImage.framework; path = System/Library/Frameworks/CoreImage.framework; sourceTree = SDKROOT; };
4445
64DDA75A188FD9140025590D /* tessdata */ = {isa = PBXFileReference; lastKnownFileType = folder; path = tessdata; sourceTree = "<group>"; };
4546
64E40AB0180C6D4D00C36DDE /* libstdc++.6.0.9.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.6.0.9.dylib"; path = "usr/lib/libstdc++.6.0.9.dylib"; sourceTree = SDKROOT; };
47+
736EFF251A5877200031B432 /* tessdata-rus */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "tessdata-rus"; path = "../TestsProject/TestsProjectTests/tessdata-rus"; sourceTree = "<group>"; };
4648
/* End PBXFileReference section */
4749

4850
/* Begin PBXFrameworksBuildPhase section */
@@ -65,6 +67,7 @@
6567
6400DDCC180C5DE000443362 = {
6668
isa = PBXGroup;
6769
children = (
70+
736EFF251A5877200031B432 /* tessdata-rus */,
6871
6400DDDE180C5DE000443362 /* Template Framework Project */,
6972
6400DDD7180C5DE000443362 /* Frameworks */,
7073
6400DDD6180C5DE000443362 /* Products */,
@@ -175,6 +178,7 @@
175178
6400DDF1180C5DE000443362 /* Images.xcassets in Resources */,
176179
428615B71845F340005D5A2E /* image_sample.jpg in Resources */,
177180
64DDA75B188FD9140025590D /* tessdata in Resources */,
181+
736EFF261A5877200031B432 /* tessdata-rus in Resources */,
178182
6400DDE3180C5DE000443362 /* InfoPlist.strings in Resources */,
179183
64DDA74E188FD7D10025590D /* Main.storyboard in Resources */,
180184
);

Tesseract-OCR-iOS.xcworkspace/xcshareddata/xcschemes/TestsProject.xcscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
BlueprintName = "TestsProjectTests"
6666
ReferencedContainer = "container:TestsProject/TestsProject.xcodeproj">
6767
</BuildableReference>
68+
<SkippedTests>
69+
<Test
70+
Identifier = "RecognitionTests">
71+
</Test>
72+
</SkippedTests>
6873
</TestableReference>
6974
</Testables>
7075
<MacroExpansion>

TesseractOCR/G8Tesseract.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
*/
4141
@property (nonatomic, copy) NSString* language;
4242

43+
/**
44+
* The path to the tessdata file, if it was specified in a call to initWithLanguage:configDictionary:configFileNames:cachesRelatedDataPath:engineMode: as a cachesRelatedDataPath
45+
* Otherwise it's supposed that the tessdata folder is located in the application bundle
46+
*/
47+
@property (nonatomic, readonly, copy) NSString *absoluteDataPath;
48+
4349
/**
4450
* The recognition mode to use. See `G8OCREngineMode` in G8Constants.h for the
4551
* available recognition modes.
@@ -228,6 +234,30 @@
228234
- (id)initWithLanguage:(NSString*)language
229235
engineMode:(G8OCREngineMode)engineMode;
230236

237+
/**
238+
* Initialize Tesseract with the provided language and engine mode.
239+
*
240+
* @param language The language to use in recognition. See `language`.
241+
* @param configDictionary A dictionary of the config variables
242+
* @param configFileNames An array of file names containing key-value config pairs. All the config
243+
* variables can be init only and debug time both. Furthermore they could be
244+
* specified at the same time, in such case tesseract will get variables from
245+
* every file and dictionary all together.
246+
* The files are searched into two folders, which are tessdata/tessconfigs and tessdata/configs
247+
* @param cachesRelatedPath If the cachesRelatedDataPath is specified, the whole content of the tessdata from the
248+
* application bundle is copied to the Library/Caches/cachesRelatedDataPath/tessdata
249+
* and tesseract is initialized with that path.
250+
* @param engineMode The engine mode to use in recognition. See `engineMode`.
251+
*
252+
* @return The initialized Tesseract object, or `nil` if there was an error.
253+
*/
254+
255+
- (id)initWithLanguage:(NSString *)language
256+
configDictionary:(NSDictionary *)configDictionary
257+
configFileNames:(NSArray *)configFileNames
258+
cachesRelatedDataPath:(NSString *)cachesRelatedDataPath
259+
engineMode:(G8OCREngineMode)engineMode NS_DESIGNATED_INITIALIZER;
260+
231261
/**
232262
* Set a Tesseract variable. See G8TesseractParameters.h for the available
233263
* options.
@@ -237,6 +267,16 @@
237267
*/
238268
- (void)setVariableValue:(NSString *)value forKey:(NSString *)key;
239269

270+
/**
271+
* Returns a Tesseract variable for the given key. See G8TesseractParameters.h for the available
272+
* options.
273+
*
274+
* @param key The option to get.
275+
*
276+
* @return returns the variable value for the given key, if it's beeb set. nil otherwise.
277+
*/
278+
- (NSString*)variableValueForKey:(NSString *)key;
279+
240280
/**
241281
* Set Tesseract variables using a dictionary. See G8TesseractParameters.h for
242282
* the available options.

0 commit comments

Comments
 (0)