Class: Gcloud::Vision::Annotation::Face::Likelihood

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/vision/annotation/face.rb

Overview

# Likelihood

A bucketized representation of likelihood of various separate facial characteristics, meant to give highly stable results across model upgrades.

See Gcloud::Vision::Annotation::Face.

Examples:

require "gcloud"

gcloud = Gcloud.new
vision = gcloud.vision

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

face.likelihood.to_h.count #=> 7
face.likelihood.sorrow? #=> false
face.likelihood.sorrow #=> "VERY_UNLIKELY"

See Also:

Constant Summary collapse

POSITIVE_RATINGS =
%w(POSSIBLE LIKELY VERY_LIKELY)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLikelihood

Returns a new instance of Likelihood.



1581
1582
1583
# File 'lib/gcloud/vision/annotation/face.rb', line 1581

def initialize
  @gapi = {}
end

Instance Attribute Details

#gapiObject



1577
1578
1579
# File 'lib/gcloud/vision/annotation/face.rb', line 1577

def gapi
  @gapi
end

Class Method Details

.from_gapi(gapi) ⇒ Object

object.



1743
1744
1745
# File 'lib/gcloud/vision/annotation/face.rb', line 1743

def self.from_gapi gapi
  new.tap { |f| f.instance_variable_set :@gapi, gapi }
end

Instance Method Details

#angerObject

Joy likelihood rating. Possible values are ‘VERY_UNLIKELY`, `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.



1622
1623
1624
# File 'lib/gcloud/vision/annotation/face.rb', line 1622

def anger
  @gapi["angerLikelihood"]
end

#anger?Boolean

Anger likelihood. Returns ‘true` if #anger is `POSSIBLE`, `LIKELY`, or `VERY_LIKELY`.

Returns:

  • (Boolean)


1632
1633
1634
# File 'lib/gcloud/vision/annotation/face.rb', line 1632

def anger?
  POSITIVE_RATINGS.include? anger
end

#blurredObject

Blurred likelihood rating. Possible values are ‘VERY_UNLIKELY`, `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.



1674
1675
1676
# File 'lib/gcloud/vision/annotation/face.rb', line 1674

def blurred
  @gapi["blurredLikelihood"]
end

#blurred?Boolean

Blurred likelihood. Returns ‘true` if #blurred is `POSSIBLE`, `LIKELY`, or `VERY_LIKELY`.

Returns:

  • (Boolean)


1684
1685
1686
# File 'lib/gcloud/vision/annotation/face.rb', line 1684

def blurred?
  POSITIVE_RATINGS.include? blurred
end

#headwearObject

Headwear likelihood rating. Possible values are ‘VERY_UNLIKELY`, `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.



1691
1692
1693
# File 'lib/gcloud/vision/annotation/face.rb', line 1691

def headwear
  @gapi["headwearLikelihood"]
end

#headwear?Boolean

Headwear likelihood. Returns ‘true` if #headwear is `POSSIBLE`, `LIKELY`, or `VERY_LIKELY`.

Returns:

  • (Boolean)


1701
1702
1703
# File 'lib/gcloud/vision/annotation/face.rb', line 1701

def headwear?
  POSITIVE_RATINGS.include? headwear
end

#inspectObject



1736
1737
1738
# File 'lib/gcloud/vision/annotation/face.rb', line 1736

def inspect
  "#<Likelihood #{self}>"
end

#joyObject

Joy likelihood rating. Possible values are ‘VERY_UNLIKELY`, `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.



1588
1589
1590
# File 'lib/gcloud/vision/annotation/face.rb', line 1588

def joy
  @gapi["joyLikelihood"]
end

#joy?Boolean

Joy likelihood. Returns ‘true` if #joy is `POSSIBLE`, `LIKELY`, or `VERY_LIKELY`.

Returns:

  • (Boolean)


1598
1599
1600
# File 'lib/gcloud/vision/annotation/face.rb', line 1598

def joy?
  POSITIVE_RATINGS.include? joy
end

#sorrowObject

Sorrow likelihood rating. Possible values are ‘VERY_UNLIKELY`, `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.



1605
1606
1607
# File 'lib/gcloud/vision/annotation/face.rb', line 1605

def sorrow
  @gapi["sorrowLikelihood"]
end

#sorrow?Boolean

Sorrow likelihood. Returns ‘true` if #sorrow is `POSSIBLE`, `LIKELY`, or `VERY_LIKELY`.

Returns:

  • (Boolean)


1615
1616
1617
# File 'lib/gcloud/vision/annotation/face.rb', line 1615

def sorrow?
  POSITIVE_RATINGS.include? sorrow
end

#surpriseObject

Surprise likelihood rating. Possible values are ‘VERY_UNLIKELY`, `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.



1639
1640
1641
# File 'lib/gcloud/vision/annotation/face.rb', line 1639

def surprise
  @gapi["surpriseLikelihood"]
end

#surprise?Boolean

Surprise likelihood. Returns ‘true` if #surprise is `POSSIBLE`, `LIKELY`, or `VERY_LIKELY`.

Returns:

  • (Boolean)


1649
1650
1651
# File 'lib/gcloud/vision/annotation/face.rb', line 1649

def surprise?
  POSITIVE_RATINGS.include? surprise
end

#to_hHash

Converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


1710
1711
1712
# File 'lib/gcloud/vision/annotation/face.rb', line 1710

def to_h
  to_hash
end

#to_hashHash

Converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


1719
1720
1721
1722
1723
# File 'lib/gcloud/vision/annotation/face.rb', line 1719

def to_hash
  { joy: joy?, sorrow: sorrow?, anger: anger?, surprise: surprise?,
    under_exposed: under_exposed?, blurred: blurred?,
    headwear: headwear? }
end

#to_sObject



1726
1727
1728
1729
1730
1731
1732
1733
# File 'lib/gcloud/vision/annotation/face.rb', line 1726

def to_s
  tmplt = "(joy?: %s, sorrow?: %s, anger?: %s, " \
            "surprise?: %s, under_exposed?: %s, blurred?: %s, " \
            "headwear: %s)"
  format tmplt, joy?.inspect, sorrow?.inspect, anger?.inspect,
         surprise?.inspect, under_exposed?.inspect, blurred?.inspect,
         headwear?.inspect
end

#under_exposedObject

Under Exposed likelihood rating. Possible values are ‘VERY_UNLIKELY`, `UNLIKELY`, `POSSIBLE`, `LIKELY`, and `VERY_LIKELY`.



1657
1658
1659
# File 'lib/gcloud/vision/annotation/face.rb', line 1657

def under_exposed
  @gapi["underExposedLikelihood"]
end

#under_exposed?Boolean

Under Exposed likelihood. Returns ‘true` if #under_exposed is `POSSIBLE`, `LIKELY`, or `VERY_LIKELY`.

Returns:

  • (Boolean)


1667
1668
1669
# File 'lib/gcloud/vision/annotation/face.rb', line 1667

def under_exposed?
  POSITIVE_RATINGS.include? under_exposed
end