Class: CVFFI::OpenSURF::ResultArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/opencv-ffi-ext/opensurf.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#inject_with_index

Constructor Details

#initialize(kp, pool) ⇒ ResultArray

Returns a new instance of ResultArray.



75
76
77
78
79
80
81
82
83
84
# File 'lib/opencv-ffi-ext/opensurf.rb', line 75

def initialize( kp, pool )
  @kp = Sequence.new(kp)
  @pool = pool
  @results = Array.new( @kp.length )

  destructor = Proc.new { poolPtr = FFI::MemoryPointer.new :pointer 
                          poolPtr.putPointer( 0, @pool ) 
                          cvReleaseMemStorage( poolPtr ) }
  ObjectSpace.define_finalizer( self, destructor )
end

Instance Attribute Details

#kpObject (readonly)

Returns the value of attribute kp.



73
74
75
# File 'lib/opencv-ffi-ext/opensurf.rb', line 73

def kp
  @kp
end

#poolObject (readonly)

Returns the value of attribute pool.



73
74
75
# File 'lib/opencv-ffi-ext/opensurf.rb', line 73

def pool
  @pool
end

Class Method Details

.from_a(a) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/opencv-ffi-ext/opensurf.rb', line 129

def self.from_a( a )
  a = YAML::load(a) if a.is_a? String
  raise "Don't know what to do" unless a.is_a? Array

  pool = CVFFI::cvCreateMemStorage(0)
  cvseq = CVFFI::OpenSURF::createOpenSURFPointSequence( pool )
  seq = Sequence.new cvseq
  
  a.each { |r|
    raise "Hm, not what I expected" unless r.length == 6
    point = CVFFI::OpenSURF::OpenSURFPoint.new( '' )
    # Hm, the embedded CvPoint buggers up initialization by hash
    point.scale = r[2]
    point.orientation = r[3]
    point.laplacian = r[4]
    d = r[5].unpack('m')[0].unpack('e64')

    d.each_with_index { |d,i| point.descriptor[i] = d }

    # r[5].unpack('e64')
    point.pt.x = r[0]
    point.pt.y = r[1]
    seq.push( point )
  }


  ra = ResultArray.new( cvseq, pool )
end

Instance Method Details

#[](i) ⇒ Object



103
104
105
# File 'lib/opencv-ffi-ext/opensurf.rb', line 103

def [](i)
  result(i)
end

#eachObject



97
98
99
100
101
# File 'lib/opencv-ffi-ext/opensurf.rb', line 97

def each
  @results.each_index { |i| 
    yield result(i) 
  }
end

#mark_on_image(img, opts) ⇒ Object



116
117
118
119
120
# File 'lib/opencv-ffi-ext/opensurf.rb', line 116

def mark_on_image( img, opts )
  each { |r|
    CVFFI::draw_circle( img, r.kp.pt, opts )
  }
end

#reset(kp) ⇒ Object



86
87
88
89
90
91
# File 'lib/opencv-ffi-ext/opensurf.rb', line 86

def reset( kp )
  @kp = Sequence.new(kp)
  @pool = kp.storage
  @results = Array.new( @kp.length )
  self
end

#result(i) ⇒ Object



93
94
95
# File 'lib/opencv-ffi-ext/opensurf.rb', line 93

def result(i)
  @results[i] ||= Result.new( @kp[i] )
end

#sizeObject Also known as: length



107
108
109
# File 'lib/opencv-ffi-ext/opensurf.rb', line 107

def size
  @kp.size
end

#to_aObject



122
123
124
125
126
127
# File 'lib/opencv-ffi-ext/opensurf.rb', line 122

def to_a
  Array.new( size ) { |i|
    r = result(i)
    [ r.x, r.y, r.scale, r.orientation, r.laplacian, r.packed_descriptor ]
    }
end

#to_CvSeqObject



112
113
114
# File 'lib/opencv-ffi-ext/opensurf.rb', line 112

def to_CvSeq
  @kp.seq
end