-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcrop_operation_integration.rb
More file actions
71 lines (53 loc) · 2.14 KB
/
crop_operation_integration.rb
File metadata and controls
71 lines (53 loc) · 2.14 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
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true
require 'mindee'
require 'mindee/v2/file_operations'
require 'mindee/v2/product'
describe Mindee::V2::FileOperation::Crop, :integration, :v2, :all_deps do
let(:crop_sample) do
File.join(V2_PRODUCT_DATA_DIR, 'crop', 'default_sample.jpg')
end
let(:v2_client) do
Mindee::V2::Client.new
end
let(:crop_model_id) do
ENV.fetch('MINDEE_V2_SE_TESTS_CROP_MODEL_ID')
end
let(:findoc_model_id) do
ENV.fetch('MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID')
end
after(:all) do
FileUtils.rm_f("#{OUTPUT_DIR}/crop_001.jpg")
FileUtils.rm_f("#{OUTPUT_DIR}/crop_002.jpg")
end
# Validates the parsed financial document response properties.
#
# @param findoc_response [Mindee::V2::InferenceResponse] The inference response to check.
def check_findoc_return(findoc_response)
expect(findoc_response.inference.model.id.length).to be > 0
expect(findoc_response.inference.result.fields['total_amount'].value).to be > 0
end
it 'extracts crops from image correctly' do
crop_input = Mindee::Input::Source::PathInputSource.new(crop_sample)
crop_params = { model_id: crop_model_id, close_file: false }
response = v2_client.enqueue_and_get_result(
Mindee::V2::Product::Crop::Crop,
crop_input,
crop_params
)
expect(response.inference.result.crops.size).to eq(2)
extracted_images = described_class.extract_crops(crop_input, response.inference.result.crops)
expect(extracted_images.size).to eq(2)
expect(extracted_images[0].filename).to eq('default_sample.jpg_page0-0.jpg')
expect(extracted_images[1].filename).to eq('default_sample.jpg_page0-1.jpg')
findoc_params = { model_id: findoc_model_id, close_file: false }
invoice0 = v2_client.enqueue_and_get_result(
Mindee::V2::Product::Extraction::Extraction,
extracted_images[0].as_input_source,
findoc_params
)
check_findoc_return(invoice0)
extracted_images.save_all_to_disk(OUTPUT_DIR)
expect(File.size(File.join(OUTPUT_DIR, 'crop_001.jpg'))).to be_between(600_000, 672_913)
expect(File.size(File.join(OUTPUT_DIR, 'crop_002.jpg'))).to be_between(600_000, 675_728)
end
end