Class: Google::Cloud::Vision::Annotation::CropHint

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

Overview

CropHint

A single crop hint that is used to generate new crops when serving images.

Examples:

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

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

crop_hints = image.crop_hints
crop_hints.count #=> 1
crop_hint = crop_hints.first

crop_hint.bounds.count #=> 4
crop_hint.bounds[0].x #=> 1
crop_hint.bounds[0].y #=> 0
crop_hint.bounds[1].x #=> 511
crop_hint.bounds[1].y #=> 0
crop_hint.bounds[2].x #=> 511
crop_hint.bounds[2].y #=> 383
crop_hint.bounds[3].x #=> 0
crop_hint.bounds[3].y #=> 383

crop_hint.confidence #=> 1.0
crop_hint.importance_fraction #=> 1.0399999618530273

Instance Method Summary collapse

Instance Method Details

#boundsArray<Vertex>

The bounding polygon for the crop region. The coordinates of the bounding box are in the original image's scale.

Returns:

  • (Array<Vertex>)

    An array of vertices.



69
70
71
72
73
74
# File 'lib/google/cloud/vision/annotation/crop_hint.rb', line 69

def bounds
  return [] unless @grpc.bounding_poly
  @bounds ||= Array(@grpc.bounding_poly.vertices).map do |v|
    Vertex.from_grpc v
  end
end

#confidenceFloat

The confidence of this being a salient region.

Returns:

  • (Float)

    A value in the range [0, 1].



81
82
83
# File 'lib/google/cloud/vision/annotation/crop_hint.rb', line 81

def confidence
  @grpc.confidence
end

#importance_fractionFloat

The fraction of importance of this salient region with respect to the original image.

Returns:

  • (Float)


91
92
93
# File 'lib/google/cloud/vision/annotation/crop_hint.rb', line 91

def importance_fraction
  @grpc.importance_fraction
end

#to_hHash

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

Returns:

  • (Hash)


100
101
102
103
# File 'lib/google/cloud/vision/annotation/crop_hint.rb', line 100

def to_h
  { bounds: bounds.map(&:to_h), confidence: confidence,
    importance_fraction: importance_fraction }
end