Class: Mindee::Parsing::Common::Ocr::MVisionV1

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/parsing/common/ocr/mvision_v1.rb

Overview

Mindee Vision V1.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prediction) ⇒ MVisionV1

Returns a new instance of MVisionV1.

Parameters:

  • prediction (Hash)


14
15
16
17
18
19
# File 'lib/mindee/parsing/common/ocr/mvision_v1.rb', line 14

def initialize(prediction)
  @pages = []
  prediction['pages'].each do |page_prediction|
    @pages.push(OcrPage.new(page_prediction))
  end
end

Instance Attribute Details

#pagesArray<OcrPage> (readonly)

List of pages.

Returns:



11
12
13
# File 'lib/mindee/parsing/common/ocr/mvision_v1.rb', line 11

def pages
  @pages
end

Instance Method Details

#reconstruct_vertically(coordinates, page_id, x_margin) ⇒ Mindee::Parsing::Common::Ocr::OcrLine

Constructs a line from a column, located underneath given coordinates start.

Parameters:

  • coordinates (Array<Mindee::Geometry::Point>)

    Polygon or bounding box where the reconstruction should

  • page_id (Integer)

    ID of the page to start at

  • x_margin (Float)

    Margin of misalignment for the x coordinate.

Returns:



37
38
39
40
41
42
43
44
45
# File 'lib/mindee/parsing/common/ocr/mvision_v1.rb', line 37

def reconstruct_vertically(coordinates, page_id, x_margin)
  line_arr = OcrLine.new([])
  @pages[page_id].all_lines.each do |line|
    line.each do |word|
      line_arr.push(word) if Geometry.below?(word.polygon, coordinates, x_margin / 2, x_margin * 2)
    end
  end
  line_arr
end

#to_sString

Returns:

  • (String)


22
23
24
25
26
27
28
29
# File 'lib/mindee/parsing/common/ocr/mvision_v1.rb', line 22

def to_s
  out_str = String.new
  @pages.map do |page|
    out_str << "\n"
    out_str << page.to_s
  end
  out_str.strip
end