Class: GOCR::Engine
- Inherits:
-
Object
- Object
- GOCR::Engine
- 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
-
#blacklist ⇒ Object
Returns the value of attribute blacklist.
-
#certainty ⇒ Object
Returns the value of attribute certainty.
-
#database ⇒ Object
Returns the value of attribute database.
-
#dust_size ⇒ Object
Returns the value of attribute dust_size.
-
#format ⇒ Object
Returns the value of attribute format.
-
#gray_level ⇒ Object
Returns the value of attribute gray_level.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#numbers_only ⇒ Object
Returns the value of attribute numbers_only.
-
#space_width ⇒ Object
Returns the value of attribute space_width.
-
#unrecognize_char ⇒ Object
Returns the value of attribute unrecognize_char.
-
#whitelist ⇒ Object
Returns the value of attribute whitelist.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Engine
constructor
A new instance of Engine.
- #text_for(arg) ⇒ Object
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(={}) .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
#blacklist ⇒ Object
Returns the value of attribute blacklist.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def blacklist @blacklist end |
#certainty ⇒ Object
Returns the value of attribute certainty.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def certainty @certainty end |
#database ⇒ Object
Returns the value of attribute database.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def database @database end |
#dust_size ⇒ Object
Returns the value of attribute dust_size.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def dust_size @dust_size end |
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def format @format end |
#gray_level ⇒ Object
Returns the value of attribute gray_level.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def gray_level @gray_level end |
#mode ⇒ Object
Returns the value of attribute mode.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def mode @mode end |
#numbers_only ⇒ Object
Returns the value of attribute numbers_only.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def numbers_only @numbers_only end |
#space_width ⇒ Object
Returns the value of attribute space_width.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def space_width @space_width end |
#unrecognize_char ⇒ Object
Returns the value of attribute unrecognize_char.
5 6 7 |
# File 'lib/gocr/engine.rb', line 5 def unrecognize_char @unrecognize_char end |
#whitelist ⇒ Object
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) );
}
|