Last active
November 19, 2016 07:41
-
-
Save Nakilon/a8b2ad295eb00b9a8d7b04d15340a07f to your computer and use it in GitHub Desktop.
snippets about Google Vision usage (for DevFest Siberia 2016)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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