Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 122 additions & 98 deletions acceptance/vision/vision_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@

describe "faces" do
it "detects faces from an image" do
analysis = vision.annotate face_image, faces: 1
annotation = vision.annotate face_image, faces: true

analysis.faces.count.must_equal 1
annotation.faces.count.must_equal 1
end

it "detects faces from an image with custom max value" do
annotation = vision.annotate face_image, faces: 1

annotation.faces.count.must_equal 1
end

it "detects faces from an image with location context" do
Expand All @@ -36,188 +42,206 @@
image.context.area.min.longitude = -122.0862462
image.context.area.max.latitude = 37.4320041
image.context.area.max.longitude = -122.0762462
analysis = vision.annotate image, faces: 1
annotation = vision.annotate image, faces: 1

analysis.faces.count.must_equal 1
annotation.faces.count.must_equal 1
end

it "detects faces from multiple images" do
analyses = vision.annotate face_image,
annotations = vision.annotate face_image,
File.open(logo_image, "rb"),
Pathname.new(landmark_image),
faces: 1

analyses.count.must_equal 3
analyses[0].faces.count.must_equal 1
analyses[1].faces.count.must_equal 0
analyses[2].faces.count.must_equal 1
annotations.count.must_equal 3
annotations[0].faces.count.must_equal 1
annotations[1].faces.count.must_equal 0
annotations[2].faces.count.must_equal 1
end
end

describe "landmarks" do
it "detects landmarks from an image" do
analysis = vision.annotate landmark_image, landmarks: 1
annotation = vision.annotate landmark_image, landmarks: true

annotation.landmarks.count.must_equal 1
end

it "detects landmarks from an image with custom max value" do
annotation = vision.annotate landmark_image, landmarks: 1

analysis.landmarks.count.must_equal 1
annotation.landmarks.count.must_equal 1
end

it "detects landmarks from multiple images" do
analyses = vision.annotate landmark_image,
annotations = vision.annotate landmark_image,
File.open(logo_image, "rb"),
landmarks: 1

analyses.count.must_equal 2
analyses[0].landmarks.count.must_equal 1
analyses[1].landmarks.count.must_equal 0
annotations.count.must_equal 2
annotations[0].landmarks.count.must_equal 1
annotations[1].landmarks.count.must_equal 0
end
end

describe "logos" do
it "detects logos from an image" do
analysis = vision.annotate logo_image, logos: 1
annotation = vision.annotate logo_image, logos: true

analysis.logos.count.must_equal 1
annotation.logos.count.must_equal 1
end

it "detects logos from an image with custom max value" do
annotation = vision.annotate logo_image, logos: 1

annotation.logos.count.must_equal 1
end

it "detects logos from multiple images" do
analyses = vision.annotate logo_image,
annotations = vision.annotate logo_image,
StringIO.new(File.read(face_image, mode: "rb")),
logos: 1

analyses.count.must_equal 2
analyses[0].logos.count.must_equal 1
analyses[1].logos.count.must_equal 0
annotations.count.must_equal 2
annotations[0].logos.count.must_equal 1
annotations[1].logos.count.must_equal 0
end
end

describe "labels" do
it "detects labels from an image" do
analysis = vision.annotate landmark_image, labels: 10
annotation = vision.annotate landmark_image, labels: true

annotation.labels.count.must_equal 6
end

it "detects labels from an image with custom max value" do
annotation = vision.annotate landmark_image, labels: 10

analysis.labels.count.must_equal 6
annotation.labels.count.must_equal 6
end

it "detects labels from multiple images" do
analyses = vision.annotate landmark_image,
annotations = vision.annotate landmark_image,
face_image,
labels: 10

analyses.count.must_equal 2
analyses[0].labels.count.must_equal 6
analyses[1].labels.count.must_equal 4
annotations.count.must_equal 2
annotations[0].labels.count.must_equal 6
annotations[1].labels.count.must_equal 4
end
end

describe "text" do
it "detects text from an image" do
analysis = vision.annotate text_image, text: true

analysis.text.text.must_include "Google Cloud Client Library for Ruby"
analysis.text.locale.must_equal "en"
analysis.text.words.count.must_equal 28
analysis.text.words[0].text.must_equal "Google"
analysis.text.words[0].bounds.map(&:to_a).must_equal [[13, 8], [53, 8], [53, 23], [13, 23]]
analysis.text.words[27].text.must_equal "Storage."
analysis.text.words[27].bounds.map(&:to_a).must_equal [[304, 59], [351, 59], [351, 74], [304, 74]]
annotation = vision.annotate text_image, text: true

annotation.text.text.must_include "Google Cloud Client Library for Ruby"
annotation.text.locale.must_equal "en"
annotation.text.words.count.must_equal 28
annotation.text.words[0].text.must_equal "Google"
annotation.text.words[0].bounds.map(&:to_a).must_equal [[13, 8], [53, 8], [53, 23], [13, 23]]
annotation.text.words[27].text.must_equal "Storage."
annotation.text.words[27].bounds.map(&:to_a).must_equal [[304, 59], [351, 59], [351, 74], [304, 74]]
end

it "detects text from multiple images" do
analyses = vision.annotate text_image,
annotations = vision.annotate text_image,
face_image,
logo_image,
text: true

analyses.count.must_equal 3
analyses[0].text.wont_be :nil?
analyses[1].text.must_be :nil?
analyses[2].text.wont_be :nil?
annotations.count.must_equal 3
annotations[0].text.wont_be :nil?
annotations[1].text.must_be :nil?
annotations[2].text.wont_be :nil?
end

it "detects text from an image with context properties" do
image = vision.image text_image
image.context.languages = ["en"]
analysis = vision.annotate image, text: true

analysis.text.text.must_include "Google Cloud Client Library for Ruby"
analysis.text.locale.must_equal "en"
analysis.text.words.count.must_equal 28
analysis.text.words[0].text.must_equal "Google"
analysis.text.words[0].bounds.map(&:to_a).must_equal [[13, 8], [53, 8], [53, 23], [13, 23]]
analysis.text.words[27].text.must_equal "Storage."
analysis.text.words[27].bounds.map(&:to_a).must_equal [[304, 59], [351, 59], [351, 74], [304, 74]]
annotation = vision.annotate image, text: true

annotation.text.text.must_include "Google Cloud Client Library for Ruby"
annotation.text.locale.must_equal "en"
annotation.text.words.count.must_equal 28
annotation.text.words[0].text.must_equal "Google"
annotation.text.words[0].bounds.map(&:to_a).must_equal [[13, 8], [53, 8], [53, 23], [13, 23]]
annotation.text.words[27].text.must_equal "Storage."
annotation.text.words[27].bounds.map(&:to_a).must_equal [[304, 59], [351, 59], [351, 74], [304, 74]]
end
end

describe "safe_search" do
it "detects safe_search from an image" do
analysis = vision.annotate face_image, safe_search: true
annotation = vision.annotate face_image, safe_search: true

analysis.safe_search.wont_be :nil?
analysis.safe_search.wont_be :adult?
analysis.safe_search.wont_be :spoof?
analysis.safe_search.wont_be :medical?
analysis.safe_search.wont_be :violence?
annotation.safe_search.wont_be :nil?
annotation.safe_search.wont_be :adult?
annotation.safe_search.wont_be :spoof?
annotation.safe_search.wont_be :medical?
annotation.safe_search.wont_be :violence?
end

it "detects safe_search from multiple images" do
analyses = vision.annotate text_image,
annotations = vision.annotate text_image,
landmark_image,
text_image,
safe_search: true

analyses.count.must_equal 3
analyses[0].safe_search.wont_be :nil?
analyses[0].safe_search.wont_be :adult?
analyses[0].safe_search.wont_be :spoof?
analyses[0].safe_search.wont_be :medical?
analyses[0].safe_search.wont_be :violence?
analyses[1].safe_search.wont_be :nil?
analyses[1].safe_search.wont_be :adult?
analyses[1].safe_search.wont_be :spoof?
analyses[1].safe_search.wont_be :medical?
analyses[1].safe_search.wont_be :violence?
analyses[2].safe_search.wont_be :nil?
analyses[2].safe_search.wont_be :adult?
analyses[2].safe_search.wont_be :spoof?
analyses[2].safe_search.wont_be :medical?
analyses[2].safe_search.wont_be :violence?
annotations.count.must_equal 3
annotations[0].safe_search.wont_be :nil?
annotations[0].safe_search.wont_be :adult?
annotations[0].safe_search.wont_be :spoof?
annotations[0].safe_search.wont_be :medical?
annotations[0].safe_search.wont_be :violence?
annotations[1].safe_search.wont_be :nil?
annotations[1].safe_search.wont_be :adult?
annotations[1].safe_search.wont_be :spoof?
annotations[1].safe_search.wont_be :medical?
annotations[1].safe_search.wont_be :violence?
annotations[2].safe_search.wont_be :nil?
annotations[2].safe_search.wont_be :adult?
annotations[2].safe_search.wont_be :spoof?
annotations[2].safe_search.wont_be :medical?
annotations[2].safe_search.wont_be :violence?
end
end

describe "properties" do
it "detects properties from an image" do
analysis = vision.annotate text_image, properties: true

analysis.properties.wont_be :nil?
analysis.properties.colors.count.must_equal 10

analysis.properties.colors[0].red.must_equal 145
analysis.properties.colors[0].green.must_equal 193
analysis.properties.colors[0].blue.must_equal 254
analysis.properties.colors[0].alpha.must_equal 1.0
analysis.properties.colors[0].rgb.must_equal "91c1fe"
analysis.properties.colors[0].score.must_equal 0.65757853
analysis.properties.colors[0].pixel_fraction.must_equal 0.16903226

analysis.properties.colors[9].red.must_equal 156
analysis.properties.colors[9].green.must_equal 214
analysis.properties.colors[9].blue.must_equal 255
analysis.properties.colors[9].alpha.must_equal 1.0
analysis.properties.colors[9].rgb.must_equal "9cd6ff"
analysis.properties.colors[9].score.must_equal 0.00096750073
analysis.properties.colors[9].pixel_fraction.must_equal 0.00064516132
annotation = vision.annotate text_image, properties: true

annotation.properties.wont_be :nil?
annotation.properties.colors.count.must_equal 10

annotation.properties.colors[0].red.must_equal 145
annotation.properties.colors[0].green.must_equal 193
annotation.properties.colors[0].blue.must_equal 254
annotation.properties.colors[0].alpha.must_equal 1.0
annotation.properties.colors[0].rgb.must_equal "91c1fe"
annotation.properties.colors[0].score.must_equal 0.65757853
annotation.properties.colors[0].pixel_fraction.must_equal 0.16903226

annotation.properties.colors[9].red.must_equal 156
annotation.properties.colors[9].green.must_equal 214
annotation.properties.colors[9].blue.must_equal 255
annotation.properties.colors[9].alpha.must_equal 1.0
annotation.properties.colors[9].rgb.must_equal "9cd6ff"
annotation.properties.colors[9].score.must_equal 0.00096750073
annotation.properties.colors[9].pixel_fraction.must_equal 0.00064516132
end

it "detects properties from multiple images" do
analyses = vision.annotate text_image,
annotations = vision.annotate text_image,
face_image,
logo_image,
properties: true

analyses.count.must_equal 3
analyses[0].properties.wont_be :nil?
analyses[1].properties.wont_be :nil?
analyses[2].properties.wont_be :nil?
annotations.count.must_equal 3
annotations[0].properties.wont_be :nil?
annotations[1].properties.wont_be :nil?
annotations[2].properties.wont_be :nil?
end
end

Expand Down
Loading