Method: Appium::Core::Base::Device::ImageComparison#match_images_features

Defined in:
lib/appium_lib_core/common/device/image_comparison.rb

#match_images_features(first_image:, second_image:, detector_name: 'ORB', match_func: 'BruteForce', good_matches_factor: nil, visualize: false) ⇒ Object

Performs images matching by features with default options. Read py_matcher for more details on this topic.

Examples:

@driver.match_images_features first_image: "image data 1", second_image: "image data 2"

visual = @@driver.match_images_features first_image: image1, second_image: image2, visualize: true
File.write 'match_images_visual.png', Base64.decode64(visual['visualization']) # if the image is PNG

Parameters:

  • first_image (String)

    An image data. All image formats, that OpenCV library itself accepts, are supported.

  • second_image (String)

    An image data. All image formats, that OpenCV library itself accepts, are supported.

  • detector_name (String) (defaults to: 'ORB')

    Sets the detector name for features matching algorithm. Some of these detectors (FAST, AGAST, GFTT, FAST, SIFT and MSER) are not available in the default OpenCV installation and have to be enabled manually before library compilation. The default detector name is ‘ORB’.

  • match_func (String) (defaults to: 'BruteForce')

    The name of the matching function. The default one is ‘BruteForce’.

  • good_matches_factor (String, nil) (defaults to: nil)

    The maximum count of “good” matches (e. g. with minimal distances). The default one is nil.

  • visualize (Bool) (defaults to: false)

    Makes the endpoint to return an image, which contains the visualized result of the corresponding picture matching operation. This option is disabled by default.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/appium_lib_core/common/device/image_comparison.rb', line 61

def match_images_features(first_image:,
                          second_image:,
                          detector_name: 'ORB',
                          match_func: 'BruteForce',
                          good_matches_factor: nil,
                          visualize: false)
  unless MATCH_FEATURES[:detector_name].member?(detector_name.to_s)
    raise ::Appium::Core::Error::ArgumentError, "detector_name should be #{MATCH_FEATURES[:detector_name]}"
  end

  unless MATCH_FEATURES[:match_func].member?(match_func.to_s)
    raise ::Appium::Core::Error::ArgumentError, "match_func should be #{MATCH_FEATURES[:match_func]}"
  end

  unless MATCH_FEATURES[:visualize].member?(visualize)
    raise ::Appium::Core::Error::ArgumentError,
          "visualize should be #{MATCH_FEATURES[:visualize]}"
  end

  options = {}
  options[:detectorName] = detector_name.to_s.upcase
  options[:matchFunc] = match_func.to_s
  options[:goodMatchesFactor] = good_matches_factor.to_i unless good_matches_factor.nil?
  options[:visualize] = visualize

  compare_images(mode: :matchFeatures, first_image: first_image, second_image: second_image, options: options)
end