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
-
#compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil) ⇒ Hash
Performs images comparison using OpenCV framework features.
-
#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.
-
#get_images_similarity(first_image:, second_image:, visualize: false) ⇒ Object
Performs images matching to calculate the similarity score between them with default options.
-
#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.
Instance Method Details
#compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil) ⇒ Hash
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.
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/appium_lib_core/common/device/image_comparison.rb', line 152 def compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil) raise "content_type should be #{MODE}" unless MODE.member?(mode) params = {} params[:mode] = mode params[:firstImage] = Base64.strict_encode64 first_image params[:secondImage] = Base64.strict_encode64 second_image params[:options] = if execute(:compare_images, {}, params) end |
#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 template_matching for more details on this topic.
105 106 107 108 109 110 111 112 113 |
# File 'lib/appium_lib_core/common/device/image_comparison.rb', line 105 def find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil) raise "visualize should be #{MATCH_TEMPLATE[:visualize]}" unless MATCH_TEMPLATE[:visualize].member?(visualize) = {} [:visualize] = visualize [:threshold] = threshold unless threshold.nil? compare_images(mode: :matchTemplate, first_image: full_image, second_image: partial_image, options: ) end |
#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.
130 131 132 133 134 135 136 137 |
# File 'lib/appium_lib_core/common/device/image_comparison.rb', line 130 def get_images_similarity(first_image:, second_image:, visualize: false) raise "visualize should be #{GET_SIMILARITY[:visualize]}" unless GET_SIMILARITY[:visualize].member?(visualize) = {} [:visualize] = visualize compare_images(mode: :getSimilarity, first_image: first_image, second_image: second_image, options: ) end |
#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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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 "detector_name should be #{MATCH_FEATURES[:detector_name]}" end unless MATCH_FEATURES[:match_func].member?(match_func.to_s) raise "match_func should be #{MATCH_FEATURES[:match_func]}" end raise "visualize should be #{MATCH_FEATURES[:visualize]}" unless MATCH_FEATURES[:visualize].member?(visualize) = {} [:detectorName] = detector_name.to_s.upcase [:matchFunc] = match_func.to_s [:goodMatchesFactor] = good_matches_factor.to_i unless good_matches_factor.nil? [:visualize] = visualize compare_images(mode: :matchFeatures, first_image: first_image, second_image: second_image, options: ) end |