phash ruby​​,如何访问哈希

时间:2014-08-08 09:09:59

标签: ruby phash

我目前开始将phash(http://www.phash.org)与ruby(https://github.com/toy/pHash/blob/master/lib/phash.rb)结合使用。

如果我使用上述示例,它可以工作。

但我想只提取哈希 - 但我不知道该怎么做

#!/usr/bin/env ruby

require 'rubygems'
require 'phash'

a = Phash::Image.new(ARGV[0])
b = Phash::Image.new(ARGV[1])

puts "a="
#output => #<Phash::ImageHash:0x00000002947080>
puts a.phash

puts "b="
#output same ..=> #<Phash::ImageHash:0x00000002946ef0>
puts b.compute_phash

# works as expected if ARGV[0]=ARGV[1] => 1.0
puts a % b

1 个答案:

答案 0 :(得分:1)

您需要的是#data方法:

> h = Phash::Image.new(p).phash
=> #<Phash::ImageHash:0x00000002515f70 @data=18314200736077351885>
> h.class
=> Phash::ImageHash
> h.methods
=> [:similarity, :data, :length, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
> h.data.class
=> Bignum
> h.data
=> 18314200736077351885
> h.data.to_s
=> "18314200736077351885"