Skip to content

Instantly share code, notes, and snippets.

@dyama
Created April 7, 2015 02:53
Show Gist options
  • Save dyama/44a9c5f629a05bbc1585 to your computer and use it in GitHub Desktop.
Save dyama/44a9c5f629a05bbc1585 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# coding: utf-8
def get_score file1,file2
def pattern path
f = 16
tmp = '/tmp/imgmatch.xbm'
`convert -level 0%,75%,0.8 -fuzz 50% -trim -resize #{f}x#{f}! #{path} #{tmp}`
ptn = File.open(tmp).read.scan(/0x[\dA-F]{2}/).map{|n| n.hex.to_s(2).rjust(8, '0')}.join.split(//)
File.delete tmp
return ptn
end
a1 = pattern file1
a2 = pattern file2
a1.zip(a2).count{|n, m| n == m}.to_f / a1.size.to_f
end
puts get_score(ARGV[0], ARGV[1]).to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment