Class: Google::Cloud::Vision::Annotation::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/vision/annotation/web.rb

Overview

Web

Relevant information for the image from the Internet.

See #web.

Examples:

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

image = vision.image "path/to/landmark.jpg"

web = image.web

entity = web.entities.first
entity.entity_id #=> "/m/019dvv"
entity.score #=> 107.34591674804688
entity.description #=> "Mount Rushmore National Memorial"

full_matching_image = web.full_matching_images.first
full_matching_image.url #=> "http://example.com/images/123.jpg"
full_matching_image.score #=> 0.10226666927337646

page_with_matching_images = web.pages_with_matching_images.first
page_with_matching_images.url #=> "http://example.com/posts/123"
page_with_matching_images.score #=> 8.114753723144531

Defined Under Namespace

Classes: Entity, Image, Page

Instance Method Summary collapse

Instance Method Details

#entitiesArray<Google::Cloud::Vision::Annotation::Web::Entity>

Deduced entities from similar images on the Internet.



67
68
69
70
71
# File 'lib/google/cloud/vision/annotation/web.rb', line 67

def entities
  @entities ||= Array(@grpc.web_entities).map do |e|
    Entity.from_grpc e
  end
end

#full_matching_imagesArray<Google::Cloud::Vision::Annotation::Web::Image>

Fully matching images from the Internet. They're definite neardups and most often a copy of the query image with merely a size change.



79
80
81
82
83
84
# File 'lib/google/cloud/vision/annotation/web.rb', line 79

def full_matching_images
  images = @grpc.full_matching_images
  @full_matching_images ||= Array(images).map do |i|
    Image.from_grpc i
  end
end

#pages_with_matching_imagesArray<Google::Cloud::Vision::Annotation::Web::Page>

Web pages containing the matching images from the Internet.



105
106
107
108
109
110
# File 'lib/google/cloud/vision/annotation/web.rb', line 105

def pages_with_matching_images
  pages = @grpc.pages_with_matching_images
  @pages_with_matching_images ||= Array(pages).map do |p|
    Page.from_grpc p
  end
end

#partial_matching_imagesArray<Google::Cloud::Vision::Annotation::Web::Image>

Partial matching images from the Internet. Those images are similar enough to share some key-point features. For example an original image will likely have partial matching for its crops.



93
94
95
96
97
98
# File 'lib/google/cloud/vision/annotation/web.rb', line 93

def partial_matching_images
  images = @grpc.partial_matching_images
  @partial_matching_images ||= Array(images).map do |i|
    Image.from_grpc i
  end
end

#to_hHash

Deeply converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


117
118
119
120
121
122
123
124
# File 'lib/google/cloud/vision/annotation/web.rb', line 117

def to_h
  {
    entities: entities.map(&:to_h),
    full_matching_images: full_matching_images.map(&:to_h),
    partial_matching_images: partial_matching_images.map(&:to_h),
    pages_with_matching_images: pages_with_matching_images.map(&:to_h)
  }
end