Class: Mindee::Parsing::Standard::PositionField
- Inherits:
-
Object
- Object
- Mindee::Parsing::Standard::PositionField
- Defined in:
- lib/mindee/parsing/standard/position_field.rb
Overview
An element's position on the image
Instance Attribute Summary collapse
- #bounding_box ⇒ Mindee::Geometry::Quadrilateral readonly
- #polygon ⇒ Mindee::Geometry::Polygon readonly
- #quadrangle ⇒ Mindee::Geometry::Quadrilateral readonly
- #rectangle ⇒ Mindee::Geometry::Quadrilateral readonly
- #value ⇒ Mindee::Geometry::Polygon readonly
Instance Method Summary collapse
-
#initialize(prediction, page_id) ⇒ PositionField
constructor
A new instance of PositionField.
-
#to_s ⇒ String
String representation.
Constructor Details
#initialize(prediction, page_id) ⇒ PositionField
Returns a new instance of PositionField.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mindee/parsing/standard/position_field.rb', line 21 def initialize(prediction, page_id) unless prediction['polygon'].nil? || prediction['polygon'].empty? @polygon = Geometry.polygon_from_prediction(prediction['polygon']) end @quadrangle = to_quadrilateral(prediction, 'quadrangle') @rectangle = to_quadrilateral(prediction, 'rectangle') @bounding_box = to_quadrilateral(prediction, 'bounding_box') @page_id = page_id || prediction['page_id'] @value = @polygon end |
Instance Attribute Details
#bounding_box ⇒ Mindee::Geometry::Quadrilateral (readonly)
17 18 19 |
# File 'lib/mindee/parsing/standard/position_field.rb', line 17 def bounding_box @bounding_box end |
#polygon ⇒ Mindee::Geometry::Polygon (readonly)
9 10 11 |
# File 'lib/mindee/parsing/standard/position_field.rb', line 9 def polygon @polygon end |
#quadrangle ⇒ Mindee::Geometry::Quadrilateral (readonly)
13 14 15 |
# File 'lib/mindee/parsing/standard/position_field.rb', line 13 def quadrangle @quadrangle end |
#rectangle ⇒ Mindee::Geometry::Quadrilateral (readonly)
15 16 17 |
# File 'lib/mindee/parsing/standard/position_field.rb', line 15 def rectangle @rectangle end |
#value ⇒ Mindee::Geometry::Polygon (readonly)
11 12 13 |
# File 'lib/mindee/parsing/standard/position_field.rb', line 11 def value @value end |
Instance Method Details
#to_s ⇒ String
String representation.
37 38 39 40 41 42 43 44 |
# File 'lib/mindee/parsing/standard/position_field.rb', line 37 def to_s return "Polygon with #{@polygon.size} points." if @polygon&.size&.positive? return "Polygon with #{@bounding_box.size} points." if @bounding_box&.size&.positive? return "Polygon with #{@rectangle.size} points." if @rectangle&.size&.positive? return "Polygon with #{@quadrangle.size} points." if @quadrangle&.size&.positive? '' end |