Skip to content

Instantly share code, notes, and snippets.

@Nakilon
Last active November 19, 2016 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nakilon/a8b2ad295eb00b9a8d7b04d15340a07f to your computer and use it in GitHub Desktop.
Save Nakilon/a8b2ad295eb00b9a8d7b04d15340a07f to your computer and use it in GitHub Desktop.
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