Class: QRTools::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/qrtools/image.rb,
ext/qrtools/qrtools_image.c

Defined Under Namespace

Classes: Point

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(path) ⇒ Object



8
9
10
11
12
# File 'ext/qrtools/qrtools_image.c', line 8

static VALUE load(VALUE klass, VALUE path)
{
  IplImage *src = cvLoadImage(StringValuePtr(path), 1);
  return Data_Wrap_Struct(klass, NULL, dealloc, src);
}

Instance Method Details

#draw_line(options) ⇒ Object

Draw a line on this image:

draw_line :from => 0, :to => 100, :thickness => 5

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/qrtools/image.rb', line 11

def draw_line options
  raise ArgumentError unless options.key?(:from)
  raise ArgumentError unless options.key?(:to)
  options = {
    :r => 255,
    :g => 0,
    :b => 0,
    :thickness => 1,
    :type => 8,
    :shift => 0,
  }.merge(options)
  native_draw_line(
    options[:from],
    options[:to],
    options[:r],
    options[:g],
    options[:b],
    options[:thickness],
    options[:type],
    options[:shift]
  )
end

#native_draw_line(from, to, r, g, b, thickness, type, shift) ⇒ Object

Draw line from from vertex to to vertex



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'ext/qrtools/qrtools_image.c', line 28

static VALUE native_draw_line(
    VALUE self,
    VALUE _from,
    VALUE _to,
    VALUE _r,
    VALUE _g,
    VALUE _b,
    VALUE _thickness,
    VALUE _type,
    VALUE _shift
) {
  IplImage * src;
  Data_Get_Struct(self, IplImage, src);
  cvLine(
      src,
      cvPoint(
        NUM2INT(rb_funcall(_from, rb_intern("x"), 0)),
        NUM2INT(rb_funcall(_from, rb_intern("y"), 0))
      ),
      cvPoint(
        NUM2INT(rb_funcall(_to, rb_intern("x"), 0)),
        NUM2INT(rb_funcall(_to, rb_intern("y"), 0))
      ),
      CV_RGB(
        NUM2INT(_r),
        NUM2INT(_g),
        NUM2INT(_b)
      ),
      NUM2INT(_thickness),
      NUM2INT(_type),
      NUM2INT(_shift)
  );
  return self;
}

#save(path) ⇒ Object



14
15
16
17
18
19
20
# File 'ext/qrtools/qrtools_image.c', line 14

static VALUE save(VALUE self, VALUE path)
{
  IplImage * src;
  Data_Get_Struct(self, IplImage, src);
  cvSaveImage(StringValuePtr(path), src);
  return self;
}

#to_nsimageObject

Convert this Image to an OSX::NSImage



36
37
38
39
40
41
# File 'lib/qrtools/image.rb', line 36

def to_nsimage
  require 'osx/cocoa'
  filename = File.join(Dir::tmpdir, 'out.jpg')
  save(filename)
  OSX::NSImage.alloc.initWithContentsOfFile filename
end