Check web page design using image file automatically
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
samples/taking_screenshot_and_match
spec
.gitignore
.rspec
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
image_match.gemspec

README.md

Gem Version Build Status

ImageMatch

An simple image match library for view test.

  • Ruby 2.3.3 and OpenCV 2.4.10 are tested.
  • Ruby 1.9.3 and OpenCV 2.4.10 are tested.

Requirement

Installation of this library

Add this line to your application's Gemfile:

gem 'image_match'

And then execute:

$ bundle

Or install it yourself as:

$ gem install image_match

Usage

Flow

Basic flow is following.

  1. Get comparison source and destination image file.
  2. Compare them with this library.

Interfaces

Following 3 functions are prepared.

  1. perfect_match function : Calc match score between image1 and image2. This function requires same size image as image1 and image2 This returns true if match score is higher than limit_similarity. When you set true to is_output, you can check matching result with image. The image will be created at your current directory.

    perfect_match(image1_filename, image2_filename, limit_similarity=0.9, is_output=false)
  2. perfect_match_template function : Try to find template image in scene image. This function requires that template image's size is smaller than scene image. This returns true if match score is higher than limit_similarity. When you set true to is_output, you can check matching result with image. The output image will be created at your current directory.

    perfect_match_template(scene_filename, template_filename, limit_similarity=0.9, is_output=false)
  3. fuzzy_match_template function : Try to find template image in scene image. This function requires that template image's size is smaller(or equal) than scene image. This function ignore image size, color and image detail. When you set true to is_output, you can check matching result with image. The output image will be created at your current directory. Note that some times this is useful I think, but accuracy is not so high currently.

    fuzzy_match_template(scene_filename, template_filename, is_output=false)
  4. match_template_ignore_size function : Try to find template image in scene image. This function requires that template image's size is smaller(or equal) than scene image. This function ignore image size. It means you can match when your template image's size is not same compared with one in scene image. When you set true to is_output, you can check matching result with image. The output image will be created at your current directory. Note that some times this is useful I think, but accuracy is not so high currently.

    match_template_ignore_size(scene_filename, template_filename, limit_similarity=0.9, is_output=false)

Sample Code

A sample to take screen shot on http://google.com/ and compare screen shot and prepared logo image. You can check all files related this sample on samples directory(currently sample is only one).

Gemfile

source 'https://rubygems.org'

gem 'capybara'
gem 'poltergeist'
gem 'image_match'

sample.rb

require 'capybara'
require 'capybara/poltergeist'
require 'image_match'
include ImageMatch

# Get current google web page image
url = 'http://google.com/'
Capybara.javascript_driver = :poltergeist
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new app, js_errors: false
end
Capybara.default_selector = :xpath

session = Capybara::Session.new(:poltergeist)
session.driver.headers = {'User-Agent' => "Mozilla/5.0 (Macintosh; Intel Mac OS X)"}
session.visit(url)

session.save_screenshot('screenshot.png', full: true)

# Compare logo (output match result image)
# Main source code related this library is following only 1 line
if perfect_match_template('./screenshot.png', './google-logo.jpg', 0.9, true)
  puts "Exists!"
else
  puts "Nothing..."
end

Result(*_match_result.png)

result

Contributing

  1. Fork it ( https://github.com/[my-github-username]/image_match/fork )
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request to develop branch Note that develop branch is newest version(not release version).

LICENSE:

The BSD Liscense

see LICENSE.txt