Class: Mindee::V1::Parsing::Common::OCR::MVisionV1

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/v1/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)


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

def initialize(prediction)
  @pages = [] # : Array[Mindee::V1::Parsing::Common::OCR::OCRPage]
  prediction['pages'].each do |page_prediction|
    @pages.push(OCRPage.new(page_prediction))
  end
end

Instance Attribute Details

#pagesArray<OCRPage> (readonly)

List of pages.

Returns:



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

def pages
  @pages
end

Instance Method Details

#reconstruct_vertically(coordinates, page_id, x_margin) ⇒ Mindee::V1::Parsing::Common::OCR::OCRLine

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

Parameters:

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

    Polygon or bounding box where the reconstruction

  • page_id (Integer)

    ID of the page to start at

  • x_margin (Float)

    Margin of misalignment for the x coordinate.

Returns:



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

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)


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

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