-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcrop_operation_spec.rb
More file actions
61 lines (46 loc) · 2.16 KB
/
crop_operation_spec.rb
File metadata and controls
61 lines (46 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true
require 'json'
require 'mini_magick' if Mindee::Dependencies.all_deps_available?
require 'mindee'
require 'mindee/v2/file_operations'
require 'mindee/v2/product'
describe Mindee::V2::FileOperation::Crop, :v2, :all_deps do
let(:crops_single_page_path) do
File.join(V2_PRODUCT_DATA_DIR, 'crop', 'default_sample.jpg')
end
let(:crops_multi_page_path) do
File.join(V2_PRODUCT_DATA_DIR, 'crop', 'multipage_sample.pdf')
end
let(:crops_single_page_json_path) do
File.join(V2_PRODUCT_DATA_DIR, 'crop', 'crop_single.json')
end
let(:crops_multi_page_json_path) do
File.join(V2_PRODUCT_DATA_DIR, 'crop', 'crop_multiple.json')
end
it 'processes single page crop split correctly' do
input_sample = Mindee::Input::Source::PathInputSource.new(crops_single_page_path)
response_hash = JSON.parse(File.read(crops_single_page_json_path))
doc = Mindee::V2::Product::Crop::CropResponse.new(response_hash)
extracted_crops = described_class.extract_crops(input_sample, doc.inference.result.crops)
expect(extracted_crops.size).to eq(1)
expect(extracted_crops[0].page_id).to eq(0)
expect(extracted_crops[0].element_id).to eq(0)
image_buffer0 = MiniMagick::Image.read(extracted_crops[0].buffer)
expect(image_buffer0.dimensions).to eq([2822, 1572])
end
it 'processes multi page receipt split correctly' do
input_sample = Mindee::Input::Source::PathInputSource.new(crops_multi_page_path)
response_hash = JSON.parse(File.read(crops_multi_page_json_path))
doc = Mindee::V2::Product::Crop::CropResponse.new(response_hash)
extracted_crops = described_class.extract_crops(input_sample, doc.inference.result.crops)
expect(extracted_crops.size).to eq(2)
expect(extracted_crops[0].page_id).to eq(0)
expect(extracted_crops[0].element_id).to eq(0)
image_buffer0 = MiniMagick::Image.read(extracted_crops[0].buffer)
expect(image_buffer0.dimensions).to eq([156, 758])
expect(extracted_crops[1].page_id).to eq(0)
expect(extracted_crops[1].element_id).to eq(1)
image_buffer1 = MiniMagick::Image.read(extracted_crops[1].buffer)
expect(image_buffer1.dimensions).to eq([187, 690])
end
end