Skip to content

Instantly share code, notes, and snippets.

@Nakilon Nakilon/google_vision.rb
Last active Nov 19, 2016

Embed
What would you like to do?
snippets about Google Vision usage (for DevFest Siberia 2016)
ENV["GCLOUD_KEYFILE"] = "./key.json"
require "gcloud"
GV = Gcloud.new("my_app").vision
GV.annotate(
GV.image("./google_vision/temp.jpg"),
labels: true,
).gapi.to_h
##############################
(L1.keys & L2.keys).empty?
(L1.keys & L2.keys).size
(L1.keys & L2.keys).size / (L1.keys | L2.keys).size
(L1.keys & L2.keys).map do |label|
L1[label] * L2[label] / popularity[label]
end.reduce(:+)
(L1.keys | L2.keys).map do |label|
((L1[label] || 0) - (L2[label] || 0)).abs
end.reduce(:+)
(L1.keys & L2.keys).map do |label|
L1[label] * L1[label] / L1.values.reduce(:+) *
L2[label] * L2[label] / L2.values.reduce(:+)
end.reduce(:+)
##############################
ENV["PHASH_LIB"] = "/usr/local/lib/libpHash.dylib"
require "phash/image"
Phash.image_similarity(
Phash.image_hash(image_1_filename),
Phash.image_hash(image_2_filename)
) > 0.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.