Class: CVFFI::BruteForceMatcher

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

Class Method Summary collapse

Class Method Details

.bestMatch(train, query, opts = {}) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/opencv-ffi-wrappers/matcher.rb', line 258

def self.bestMatch( train, query, opts = {})
  maxDistance = opts[:max_distance] || nil
  k = opts[:k] || nil

  results = MatchResults.new( train, query )
  query.each_with_index { |q,qidx|

    this_result = []
    train.each_with_index { |t,tidx|
      distance = block_given? ? yield( t,q ) : t.distance_to(q)

      ## Non-optimized algorithms...
      if maxDistance
        if distance < maxDistance
          this_result <<  MatchResult.new( tidx, qidx, distance )
        end
      elsif k
        if this_result.length < k
          this_result << MatchResult.new( tidx, qidx, distance )
        else
          this_result.sort! { |a,b| a.distance <=> b.distance }
          if distance < this_result[0].distance
            this_result[0] = MatchResult.new( tidx, qidx, distance )
          end
        end
      else
        if this_result.length == 0 or distance < this_result[0].distance
          this_result = [ MatchResult.new( tidx, qidx, distance ) ]
        end
      end

    }
    this_result.each { |r| results.add_result( r ) }
  }

  results
end

.euclidian_distance(a, b) ⇒ Object



253
254
255
256
# File 'lib/opencv-ffi-wrappers/matcher.rb', line 253

def self.euclidian_distance( a, b )


end