Module: Appium::Core::Base::Device::ImageComparison

Included in:
Bridge::MJSONWP, Bridge::W3C
Defined in:
lib/appium_lib_core/common/device/image_comparison.rb

Constant Summary collapse

MODE =
[:matchFeatures, :getSimilarity, :matchTemplate].freeze
MATCH_FEATURES =
{
  detector_name: %w(AKAZE AGAST BRISK FAST GFTT KAZE MSER SIFT ORB),
  match_func: %w(FlannBased BruteForce BruteForceL1 BruteForceHamming BruteForceHammingLut BruteForceSL2),
  goodMatchesFactor: nil, # Integer
  visualize: [true, false]
}.freeze
MATCH_TEMPLATE =
{
  visualize: [true, false]
}.freeze
GET_SIMILARITY =
{
  visualize: [true, false]
}.freeze

Instance Method Summary collapse

Instance Method Details

#compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil) ⇒ Object

Performs images comparison using OpenCV framework features. It is expected that both OpenCV framework and opencv4nodejs module are installed on the machine where Appium server is running.

Parameters:

  • mode: (Symbol) (defaults to: :matchFeatures)

    One of possible comparison modes: ‘:matchFeatures`, `:getSimilarity`, `:matchTemplate`. `:matchFeatures is by default.

  • 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.

  • options: (Hash) (defaults to: nil)

    The content of this dictionary depends on the actual ‘mode` value. See the documentation on `appium-support` module for more details.



# File 'lib/appium_lib_core/common/device/image_comparison.rb', line 85


#find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil) ⇒ Object

Performs images matching by template to find possible occurrence of the partial image in the full image with default options. Read docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html for more details on this topic.

Examples:

@driver.find_image_occurrence full_image: "image data 1", partial_image: "image data 2"

visual = @@driver.find_image_occurrence full_image: image1, partial_image: image2, visualize: true
File.write 'find_result_visual.png', Base64.decode64(visual['visualization']) # if the image is PNG

Parameters:

  • full_image: (String)

    A full image data.

  • partial_image: (String)

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

  • visualise: (Bool)

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

  • threshold: (Float) (defaults to: nil)
    0.5

    At what normalized threshold to reject



# File 'lib/appium_lib_core/common/device/image_comparison.rb', line 49


#get_images_similarity(first_image:, second_image:, visualize: false) ⇒ Object

Performs images matching to calculate the similarity score between them with default options. The flow there is similar to the one used in ‘find_image_occurrence` but it is mandatory that both images are of equal size.

Examples:

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

visual = @@driver.get_images_similarity first_image: image1, second_image: image2, visualize: true
File.write 'images_similarity_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.

  • visualise: (Bool)

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



# File 'lib/appium_lib_core/common/device/image_comparison.rb', line 68


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

class << self



# File 'lib/appium_lib_core/common/device/image_comparison.rb', line 25