motion-ocr 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a274f9c83916a0294a98708646178a2a6ca2964d
4
+ data.tar.gz: 029fbbfd7614ba1d36f8dc2fcf7ec3c90f55f21a
5
+ SHA512:
6
+ metadata.gz: fb68853812fcef42a7d352676e32da6526c03dd3a25729c33df4c5c95877e9dcd3cb378b3357080e21cc6e6bb3cf59309a34a7ee25f88d4100c844b15cd0b581
7
+ data.tar.gz: d70e53de63da7bee37206ddf18d93698e5e05c275835292163c209a2a11ad41a07ad6bdfdb6b49631cf908d5d48476f5806bd99bc540d447c3615f9e9674a63a
data/README.md CHANGED
@@ -10,13 +10,28 @@ First, install the gem:
10
10
 
11
11
  Then, reference it in your RubyMotion project Rakefile:
12
12
 
13
+ # -*- coding: utf-8 -*-
14
+ $:.unshift("/Library/RubyMotion/lib")
15
+ require 'motion/project/template/ios'
16
+
13
17
  require 'motion-ocr'
14
18
 
15
19
  And that's it. Build your project and MotionOCR will be ready for action.
16
20
 
17
21
  ### Use
18
22
 
19
- ocr = MotionOCR.new
23
+ ocr = Motion::OCR.new
20
24
  image_with_text = UIImage.imageNamed('phototest.gif').CGImage
21
25
 
22
26
  ocr.scan(image_with_text) # returns a String containing the detected text in the image
27
+
28
+ ### Options
29
+
30
+ You use your own Tesseract language file
31
+ (available at https://code.google.com/p/tesseract-ocr/downloads/list).
32
+
33
+ Put the language file (e.g., `spa.traineddata`) into your app's
34
+ `ressources/tessdata` directory.
35
+ Then pass the language to MotionOCR:
36
+
37
+ ocr = Motion::OCR.new language: 'spa'
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "bundler/gem_tasks"
3
3
  $:.unshift("/Library/RubyMotion/lib")
4
- require 'motion/project'
4
+ require 'motion/project/template/ios'
5
5
 
6
6
  Bundler.setup
7
7
  Bundler.require
@@ -14,4 +14,3 @@ Motion::Project::App.setup do |app|
14
14
  app.deployment_target = '5.0'
15
15
 
16
16
  end
17
-
@@ -0,0 +1,19 @@
1
+ module Motion
2
+ class OCR
3
+ def initialize(options={})
4
+ options[:language] ||= "eng"
5
+ @motion_ocr = MotionOCR.alloc.initWithOptions stringify(options)
6
+ end
7
+
8
+ def scan(image)
9
+ @motion_ocr.scan image
10
+ end
11
+
12
+ private
13
+
14
+ def stringify(hash)
15
+ stringified = hash.flatten.map(&:to_s)
16
+ Hash[*stringified]
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module MotionOCR
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,13 +1,45 @@
1
- describe MotionOCR do
1
+ # encoding: UTF-8
2
2
 
3
- before do
4
- @ocr = MotionOCR.new
5
- end
3
+ describe Motion::OCR do
6
4
 
7
5
  it "can detect the text in the sample image" do
8
- image_with_text = UIImage.imageWithContentsOfFile(File.expand_path('../support/phototest.gif', __FILE__)).CGImage
6
+ ocr = Motion::OCR.new
7
+
8
+ ocr.scan(image 'phototest').should == <<-EOF.gsub(/^\W\W+/, '')
9
+ This is a lot of 12 point text to test the
10
+ ocr code and see if it works on all types
11
+ of file format.
12
+ The quick brown dog jumped over the
13
+ lazy fox. The quick brown dog jumped
14
+ over the lazy fox. The quick brown dog
15
+ jumped over the lazy fox. The quick
16
+ brown dog jumped over the lazy fox.
17
+
18
+ EOF
19
+ end
20
+
21
+ it "accepts the language as parameter" do
22
+ install_language :deu
23
+ ocr = Motion::OCR.new language: "deu"
24
+
25
+ ocr.scan(image 'phototest_german').should == <<-EOF.gsub(/^\W\W+/, '')
26
+ Weit hinten, hinter den Wortbergen,
27
+ fern der Länder Vokalien und Konsonantien
28
+ leben die Blindtexte.
29
+ Abgeschieden wohnen sie in Buchstabhausen
30
+ an der Küste des Semantik,
31
+ eines großen Sprachozeans.
32
+ Ein kleines Bächlein namens Duden
33
+ fließt durch ihren Ort
34
+ und versorgt sie mit den nötigen Regelialien.
35
+
36
+ EOF
37
+ end
9
38
 
10
- @ocr.scan(image_with_text).should == <<-EOF.gsub(/^ /, '')
39
+ it "still works with the old constructor" do
40
+ ocr = MotionOCR.new
41
+
42
+ ocr.scan(image 'phototest').should == <<-EOF.gsub(/^\W\W+/, '')
11
43
  This is a lot of 12 point text to test the
12
44
  ocr code and see if it works on all types
13
45
  of file format.
@@ -20,4 +52,18 @@ describe MotionOCR do
20
52
  EOF
21
53
  end
22
54
 
55
+ def image(image_name)
56
+ UIImage.imageWithContentsOfFile(file("#{image_name}.gif")).CGImage
57
+ end
58
+
59
+ def file(file_name)
60
+ File.expand_path("../support/#{file_name}", __FILE__)
61
+ end
62
+
63
+ def install_language(language)
64
+ documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)
65
+ targetPath = "#{documentPaths.first}/tessdata/#{language}.traineddata"
66
+ fileManager = NSFileManager.defaultManager
67
+ fileManager.copyItemAtPath file("#{language}.traineddata"), toPath: targetPath, error: nil
68
+ end
23
69
  end
@@ -18,5 +18,6 @@ namespace tesseract {
18
18
  uint32_t *pixels;
19
19
  }
20
20
 
21
+ - (id)initWithOptions:(NSDictionary*)options;
21
22
  - (NSString *)scan:(id)image;
22
23
  @end
@@ -16,32 +16,36 @@
16
16
  @implementation MotionOCR
17
17
 
18
18
  - (id)init {
19
- self = [super init];
20
-
21
- if (self) {
22
- // Set up the tessdata path. This is included in the application bundle
23
- // but is copied to the Documents directory on the first run.
24
- NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
25
- NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil;
26
-
27
- NSString *dataPath = [documentPath stringByAppendingPathComponent:@"tessdata"];
28
- NSFileManager *fileManager = [NSFileManager defaultManager];
29
- // If the expected store doesn't exist, copy the default store.
30
- if (![fileManager fileExistsAtPath:dataPath]) {
31
- // get the path to the app bundle (with the tessdata dir)
32
- NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
33
- NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"];
34
- if (tessdataPath) {
35
- [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
36
- }
37
- }
38
-
39
- setenv("TESSDATA_PREFIX", [[documentPath stringByAppendingString:@"/"] UTF8String], 1);
40
-
41
- tesseract = new tesseract::TessBaseAPI();
42
- tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], "eng");
43
- }
44
- return self;
19
+ return [self initWithOptions:@{}];
20
+ }
21
+
22
+ - (id)initWithOptions:(NSDictionary*)options {
23
+ self = [super init];
24
+
25
+ if (self) {
26
+ // Set up the tessdata path. This is included in the application bundle
27
+ // but is copied to the Documents directory on the first run.
28
+ NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
29
+ NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil;
30
+
31
+ NSString *dataPath = [documentPath stringByAppendingPathComponent:@"tessdata"];
32
+ NSFileManager *fileManager = [NSFileManager defaultManager];
33
+ // If the expected store doesn't exist, copy the default store.
34
+ if (![fileManager fileExistsAtPath:dataPath]) {
35
+ // get the path to the app bundle (with the tessdata dir)
36
+ NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
37
+ NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"];
38
+ if (tessdataPath) {
39
+ [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
40
+ }
41
+ }
42
+
43
+ setenv("TESSDATA_PREFIX", [[documentPath stringByAppendingString:@"/"] UTF8String], 1);
44
+
45
+ tesseract = new tesseract::TessBaseAPI();
46
+ tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], [options[@"language"] UTF8String]);
47
+ }
48
+ return self;
45
49
  }
46
50
 
47
51
  - (void)dealloc {
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-ocr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Fernando Espinosa Jiménez
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-05 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Allows to perform text detection inside images in an easy way.
15
14
  email:
@@ -18,7 +17,7 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
- - .gitignore
20
+ - ".gitignore"
22
21
  - Gemfile
23
22
  - Gemfile.lock
24
23
  - LICENSE
@@ -26,12 +25,15 @@ files:
26
25
  - Rakefile
27
26
  - app/app_delegate.rb
28
27
  - lib/motion-ocr.rb
28
+ - lib/motion-ocr/ocr.rb
29
29
  - lib/motion-ocr/version.rb
30
30
  - motion-ocr.gemspec
31
31
  - resources/tessdata/configs/nodict
32
32
  - resources/tessdata/eng.traineddata
33
33
  - spec/motion_ocr_spec.rb
34
+ - spec/support/deu.traineddata
34
35
  - spec/support/phototest.gif
36
+ - spec/support/phototest_german.gif
35
37
  - vendor/MotionOCR/MotionOCR.bridgesupport
36
38
  - vendor/MotionOCR/MotionOCR.xcodeproj/project.pbxproj
37
39
  - vendor/MotionOCR/MotionOCR.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -86,28 +88,29 @@ files:
86
88
  - vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/lib/libtesseract_all.a
87
89
  homepage: https://github.com/ferdev/motion-ocr
88
90
  licenses: []
91
+ metadata: {}
89
92
  post_install_message:
90
93
  rdoc_options: []
91
94
  require_paths:
92
95
  - lib
93
96
  required_ruby_version: !ruby/object:Gem::Requirement
94
- none: false
95
97
  requirements:
96
- - - ! '>='
98
+ - - ">="
97
99
  - !ruby/object:Gem::Version
98
100
  version: '0'
99
101
  required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
102
  requirements:
102
- - - ! '>='
103
+ - - ">="
103
104
  - !ruby/object:Gem::Version
104
105
  version: '0'
105
106
  requirements: []
106
107
  rubyforge_project:
107
- rubygems_version: 1.8.24
108
+ rubygems_version: 2.2.2
108
109
  signing_key:
109
- specification_version: 3
110
+ specification_version: 4
110
111
  summary: A RubyMotion wrapper for the OCR engine, Tesseract
111
112
  test_files:
112
113
  - spec/motion_ocr_spec.rb
114
+ - spec/support/deu.traineddata
113
115
  - spec/support/phototest.gif
116
+ - spec/support/phototest_german.gif