Class: CVFFI::ImagePatch::ResultsArray

Inherits:
Array
  • Object
show all
Defined in:
lib/opencv-ffi-wrappers/features2d/image_patch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, mask = nil) ⇒ ResultsArray

Returns a new instance of ResultsArray.



132
133
134
135
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 132

def initialize( params, mask = nil )
  @params = params
  @mask = mask || Mask::make( params )
end

Instance Attribute Details

#maskObject (readonly)

Returns the value of attribute mask.



130
131
132
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 130

def mask
  @mask
end

Class Method Details

.from_a(a, params = {}) ⇒ Object



147
148
149
150
151
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 147

def self.from_a(a, params = {} )
  r = ResultsArray.new( Params.new params )
  a.each { |a| r << Result.from_a( a ) }
  r
end

Instance Method Details

#draw_index_image(opts = {}) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 153

def draw_index_image( opts = {} )
  border = 5
  max_cols = opts[:max_cols] || 20 

  # Aim for square index
  cols = Math::sqrt(size).ceil
  cols = [cols,max_cols].min

  rows = (size*1.0/cols).ceil
#  puts "Building index #{cols} x #{rows}"
#  puts "Image patch size #{patch_size}"

  img_size = CVFFI::CvSize.new( [ (cols)*(patch_size+border) + border, (rows)*(patch_size+border) + border ] )

  img = CVFFI::cvCreateImage(img_size, 8, 1 )
  CVFFI::cvSet( img, CVFFI::CvScalar.new( [ 200.0,0.0,0.0,0.0 ] ), nil )

  each_with_index { |patch,i|
    c = i%cols
    r = (i/cols).floor

    xoffset = c*(patch_size+border)+border
    yoffset = r*(patch_size+border)+border

#    puts "Offsets: #{xoffset} x #{yoffset}"

    patch.oriented_patch.each_with_indices { |value, i, j|
        if mask.valid?(i,j)
          CVFFI::cvSet2D( img, yoffset+i, xoffset+j, CVFFI::CvScalar.new( [ value, 0, 0, 0 ] ) )
        end
    }
  }

  img
end

#patch_sizeObject



137
138
139
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 137

def patch_size
  @params.size
end

#to_aObject



141
142
143
144
145
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 141

def to_a
  each.map { |r|
    r.to_a
  }
end