Sha256: 53675f991ebacaaa086905c592d816ee6699ee44c7b92a2223713b6425dc0a94

Contents?: true

Size: 1.02 KB

Versions: 49

Compression:

Stored size: 1.02 KB

Contents

require 'RMagick'

#   The Image#find_similar_region searches for a region in the image
#   similar to the target. This example uses a rectangle from the image
#   as the target, assuring that find_similar_region will succeed.

#   Draw a red rectangle over the image that shows where the target matched.

img = Magick::Image.read('../doc/ex/images/Flower_Hat.jpg').first
target = img.crop(21, 94, 118, 126)

begin
    res = img.find_similar_region(target)
    if res
        gc = Magick::Draw.new
        gc.stroke('red')
        gc.stroke_width(2)
        gc.fill('none')
        gc.rectangle(res[0], res[1], res[0]+target.columns, res[1]+target.rows)
        gc.draw(img)
        img.matte = false
        puts "Found similar region. Writing `find_similar_region.gif'..."
        img.write('find_similar_region.gif')
    else
        puts "No match!"
    end
rescue NotImplementedError
    $stderr.puts <<-END_MSG
    The find_similar_region method is not supported by this version of
    ImageMagick/GraphicsMagick.
    END_MSG
end

exit

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
rmagick-2.13.4 examples/find_similar_region.rb
rmagick-2.13.3 examples/find_similar_region.rb
rmagick-2.13.3.rc1 examples/find_similar_region.rb
rmagick-2.13.2 examples/find_similar_region.rb
rdp-rmagick-0.0.0 examples/find_similar_region.rb
rmagick-2.13.1 examples/find_similar_region.rb
rmagick-2.12.2 examples/find_similar_region.rb
rmagick-2.12.1 examples/find_similar_region.rb
rmagick-2.12.0 examples/find_similar_region.rb
rmagick-2.11.1 examples/find_similar_region.rb
rmagick-2.10.0 examples/find_similar_region.rb
rmagick-2.11.0 examples/find_similar_region.rb
rmagick-1.15.0 examples/find_similar_region.rb
rmagick-1.14.1 examples/find_similar_region.rb
rmagick-1.14.0 examples/find_similar_region.rb
rmagick-1.15.10 examples/find_similar_region.rb
rmagick-1.15.1 examples/find_similar_region.rb
rmagick-1.15.15 examples/find_similar_region.rb
rmagick-1.15.13 examples/find_similar_region.rb
rmagick-1.15.14 examples/find_similar_region.rb