Class: GOCR::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/gocr/engine.rb,
ext/gocr/gocr.c

Constant Summary collapse

FORMATS =
Hash[%w(UTF8 ISO8859_1 TeX HTML XML ASCII).map.with_index.to_a].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Engine

Returns a new instance of Engine.



10
11
12
13
14
15
16
17
# File 'lib/gocr/engine.rb', line 10

def initialize(options={})
  options.each do |k, v|
    send("#{k}=", v) if respond_to?(k)
  end
  @format = FORMATS[format].to_i
  @dust_size = -1 if dust_size.nil?
  @unrecognize_char = @unrecognize_char[0] unless unrecognize_char.nil?
end

Instance Attribute Details

#blacklistObject

Returns the value of attribute blacklist.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def blacklist
  @blacklist
end

#certaintyObject

Returns the value of attribute certainty.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def certainty
  @certainty
end

#databaseObject

Returns the value of attribute database.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def database
  @database
end

#dust_sizeObject

Returns the value of attribute dust_size.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def dust_size
  @dust_size
end

#formatObject

Returns the value of attribute format.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def format
  @format
end

#gray_levelObject

Returns the value of attribute gray_level.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def gray_level
  @gray_level
end

#modeObject

Returns the value of attribute mode.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def mode
  @mode
end

#numbers_onlyObject

Returns the value of attribute numbers_only.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def numbers_only
  @numbers_only
end

#space_widthObject

Returns the value of attribute space_width.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def space_width
  @space_width
end

#unrecognize_charObject

Returns the value of attribute unrecognize_char.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def unrecognize_char
  @unrecognize_char
end

#whitelistObject

Returns the value of attribute whitelist.



5
6
7
# File 'lib/gocr/engine.rb', line 5

def whitelist
  @whitelist
end

Instance Method Details

#text_for(arg) ⇒ Object



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'ext/gocr/gocr.c', line 403

static VALUE image_recognize(VALUE self, VALUE arg) {
    VALUE tmp;

    job_t job1, *job; /* fixme, dont want global variables for lib */
    job=OCR_JOB=&job1;
    job_init(job);
    
    job->src.fname = StringValuePtr(arg);
    tmp = rb_iv_get(self, "@database");
    if (tmp != Qnil) {
        job->cfg.db_path = StringValuePtr(tmp);
    }
    tmp = rb_iv_get(self, "@format");
    if (tmp != Qnil) {
        job->cfg.out_format = NUM2INT(tmp);
    }
    tmp = rb_iv_get(self, "@whitelist");
    if (tmp != Qnil) {
        if (strlen(StringValuePtr(tmp)) > 0)
            job->cfg.cfilter = StringValuePtr(tmp);
    }
    tmp = rb_iv_get(self, "@dust_size");
    if (tmp != Qnil) {
        job->cfg.dust_size = NUM2INT(tmp);
    }
    tmp = rb_iv_get(self, "@gray_level");
    if (tmp != Qnil) {
        job->cfg.cs = NUM2INT(tmp);
    }
    tmp = rb_iv_get(self, "@space_width");
    if (tmp != Qnil) {
        job->cfg.spc = NUM2INT(tmp);
    }
    tmp = rb_iv_get(self, "@mode");
    if (tmp != Qnil) {
        job->cfg.mode |= NUM2INT(tmp);
    }
    tmp = rb_iv_get(self, "@numbers_only");
    if (tmp == Qtrue) {
        job->cfg.only_numbers = 1;
    }
    tmp = rb_iv_get(self, "@certainty");
    if (tmp != Qnil) {
        job->cfg.certainty = NUM2INT(tmp);
    }
    tmp = rb_iv_get(self, "@unrecognize_char");
    if (tmp != Qnil) {
        job->cfg.unrec_marker = StringValuePtr(tmp)[0];
    }
    return rb_str_new2( gocr_main(job) );
}