Skip to content

Commit

Permalink
Merge pull request #164 from atomic-labs/jmah-cleanup
Browse files Browse the repository at this point in the history
Sundry clean-ups.
  • Loading branch information
Kevin Conley committed Apr 23, 2015
2 parents 07332c5 + c0fa765 commit 331afd9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
Empty file modified TesseractOCR/G8Tesseract.h
100755 → 100644
Empty file.
40 changes: 18 additions & 22 deletions TesseractOCR/G8Tesseract.mm
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ @interface G8Tesseract () {
@implementation G8Tesseract

+ (void)initialize {

[super initialize];

if (self == [G8Tesseract self]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveMemoryWarningNotification:)
Expand Down Expand Up @@ -143,15 +140,15 @@ - (id)initWithLanguage:(NSString *)language
_rect = CGRectZero;

_monitor = new ETEXT_DESC();
_monitor->cancel = (CANCEL_FUNC)[self methodForSelector:@selector(tesseractCancelCallbackFunction:)];
_monitor->cancel = tesseractCancelCallbackFunction;
_monitor->cancel_this = (__bridge void*)self;

if (self.absoluteDataPath == nil) {
// config Tesseract to search trainedData in tessdata folder of the application bundle];
_absoluteDataPath = [NSString stringWithFormat:@"%@", [NSString stringWithString:[NSBundle mainBundle].bundlePath]].copy;
_absoluteDataPath = [NSBundle mainBundle].bundlePath;
}

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

_tesseract = new tesseract::TessBaseAPI();

Expand All @@ -166,7 +163,7 @@ - (id)initWithLanguage:(NSString *)language
- (void)dealloc
{
if (_monitor != nullptr) {
free(_monitor);
delete _monitor;
_monitor = nullptr;
}
if (_tesseract != nullptr) {
Expand All @@ -180,22 +177,19 @@ - (void)dealloc

- (BOOL)configEngine
{
GenericVector<STRING> tessKeys;
for( NSString *key in self.configDictionary.allKeys ){
__block GenericVector<STRING> tessKeys;
__block GenericVector<STRING> tessValues;
[self.configDictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *val, BOOL *stop) {
tessKeys.push_back(STRING(key.UTF8String));
}

GenericVector<STRING> tessValues;
for( NSString *val in self.configDictionary.allValues ){
tessValues.push_back(STRING(val.UTF8String));
}
}];

int count = (int)self.configFileNames.count;
const char **configs = count ? (const char **)malloc(sizeof(const char *) * count) : NULL;
for (int i = 0; i < count; i++) {
configs[i] = ((NSString*)self.configFileNames[i]).UTF8String;
configs[i] = ((NSString*)self.configFileNames[i]).fileSystemRepresentation;
}
int returnCode = _tesseract->Init(self.absoluteDataPath.UTF8String, self.language.UTF8String,
int returnCode = _tesseract->Init(self.absoluteDataPath.fileSystemRepresentation, self.language.UTF8String,
(tesseract::OcrEngineMode)self.engineMode,
(char **)configs, count,
&tessKeys, &tessValues,
Expand Down Expand Up @@ -304,18 +298,16 @@ - (NSString*)variableValueForKey:(NSString *)key {

- (void)setVariablesFromDictionary:(NSDictionary *)dictionary
{
for (NSString *key in dictionary.allKeys) {
NSString *value = dictionary[key];
[dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
[self setVariableValue:value forKey:key];
}
}];
}

- (void)loadVariables
{
for (NSString *key in self.variables.allKeys) {
NSString *value = self.variables[key];
[self.variables enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
_tesseract->SetVariable(key.UTF8String, value.UTF8String);
}
}];
}

#pragma mark - Getters and setters
Expand Down Expand Up @@ -858,4 +850,8 @@ - (BOOL)tesseractCancelCallbackFunction:(int)words
return isCancel;
}

static bool tesseractCancelCallbackFunction(void *cancel_this, int words) {
return [(__bridge G8Tesseract *)cancel_this tesseractCancelCallbackFunction:words];
}

@end
Empty file modified TesseractOCR/README_tesseract.md
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion TesseractOCR/build_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ cd -
# Start clean
#######################

rm -rf GLOBAL_OUTDIR lib include
rm -rf $GLOBAL_OUTDIR lib include

#######################
# LEPTONLIB
Expand Down

0 comments on commit 331afd9

Please sign in to comment.