0

我目前正在结合 ruby​​ ( https://github.com/toy/pHash/blob/master/lib/phash.rb ) 使用phash ( http://www.phash.org )。

如果我使用所描述的示例,它会起作用。

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

#!/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
4

1 回答 1

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"
于 2014-08-08T10:46:01.097 回答