line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AsposeOcrCloud::OcrApi; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.6.0; |
4
|
1
|
|
|
1
|
|
163836
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
3
|
use utf8; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
55
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
8
|
1
|
|
|
1
|
|
4
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
9
|
1
|
|
|
1
|
|
4
|
use Log::Any qw($log); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
10
|
1
|
|
|
1
|
|
150
|
use File::Slurp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
89
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
424
|
use AsposeOcrCloud::ApiClient; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
54
|
|
13
|
1
|
|
|
1
|
|
9
|
use AsposeOcrCloud::Configuration; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1308
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $VERSION = '1.01'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
19
|
0
|
0
|
|
|
|
|
my $default_api_client = $AsposeOcrCloud::Configuration::api_client ? $AsposeOcrCloud::Configuration::api_client : |
20
|
|
|
|
|
|
|
AsposeOcrCloud::ApiClient->new; |
21
|
0
|
|
|
|
|
|
my (%self) = ( |
22
|
|
|
|
|
|
|
'api_client' => $default_api_client, |
23
|
|
|
|
|
|
|
@_ |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#my $self = { |
27
|
|
|
|
|
|
|
# #api_client => $options->{api_client} |
28
|
|
|
|
|
|
|
# api_client => $default_api_client |
29
|
|
|
|
|
|
|
#}; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
bless \%self, $class; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# PostOcrFromUrlOrContent |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
# Recognize image text from some url if provided or from the request body content, language can be selected, default dictionaries can be used for correction. |
39
|
|
|
|
|
|
|
# |
40
|
|
|
|
|
|
|
# @param String $url The image file url. (optional) |
41
|
|
|
|
|
|
|
# @param String $language Language of the document. (optional) |
42
|
|
|
|
|
|
|
# @param Boolean $useDefaultDictionaries Use default dictionaries for result correction. (optional) |
43
|
|
|
|
|
|
|
# @param File $file (required) |
44
|
|
|
|
|
|
|
# @return OCRResponse |
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
sub PostOcrFromUrlOrContent { |
47
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# parse inputs |
51
|
0
|
|
|
|
|
|
my $_resource_path = '/ocr/recognize/?appSid={appSid}&url={url}&language={language}&useDefaultDictionaries={useDefaultDictionaries}'; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q&\E/&/g; |
54
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q\/?\E/?/g; |
55
|
0
|
|
|
|
|
|
$_resource_path =~ s/\QtoFormat={toFormat}\E/format={format}/g; |
56
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{path}\E/{Path}/g; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $_method = 'POST'; |
59
|
0
|
|
|
|
|
|
my $query_params = {}; |
60
|
0
|
|
|
|
|
|
my $header_params = {}; |
61
|
0
|
|
|
|
|
|
my $form_params = {}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# 'Accept' and 'Content-Type' header |
64
|
0
|
|
|
|
|
|
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json'); |
65
|
0
|
0
|
|
|
|
|
if ($_header_accept) { |
66
|
0
|
|
|
|
|
|
$header_params->{'Accept'} = $_header_accept; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
$header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('multipart/form-data'); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# query params |
71
|
0
|
0
|
|
|
|
|
if ( exists $args{'url'}) { |
72
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{url}\E/$args{'url'}/g; |
73
|
|
|
|
|
|
|
}else{ |
74
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]url.*?(?=&|\?|$)//g; |
75
|
|
|
|
|
|
|
}# query params |
76
|
0
|
0
|
|
|
|
|
if ( exists $args{'language'}) { |
77
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{language}\E/$args{'language'}/g; |
78
|
|
|
|
|
|
|
}else{ |
79
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]language.*?(?=&|\?|$)//g; |
80
|
|
|
|
|
|
|
}# query params |
81
|
0
|
0
|
|
|
|
|
if ( exists $args{'useDefaultDictionaries'}) { |
82
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{useDefaultDictionaries}\E/$args{'useDefaultDictionaries'}/g; |
83
|
|
|
|
|
|
|
}else{ |
84
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]useDefaultDictionaries.*?(?=&|\?|$)//g; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $_body_data; |
89
|
|
|
|
|
|
|
# form params |
90
|
0
|
0
|
|
|
|
|
if ( exists $args{'file'} ) { |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$_body_data = read_file( $args{'file'} , binmode => ':raw' ); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# authentication setting, if any |
100
|
0
|
|
|
|
|
|
my $auth_settings = []; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# make the API Call |
103
|
0
|
|
|
|
|
|
my $response = $self->{api_client}->call_api($_resource_path, $_method, |
104
|
|
|
|
|
|
|
$query_params, $form_params, |
105
|
|
|
|
|
|
|
$header_params, $_body_data, $auth_settings); |
106
|
0
|
0
|
|
|
|
|
if (!$response) { |
107
|
0
|
|
|
|
|
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if($AsposeOcrCloud::Configuration::debug){ |
111
|
0
|
|
|
|
|
|
print "\nResponse Content: ".$response->content; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $_response_object = $self->{api_client}->pre_deserialize($response->content, 'OCRResponse', $response->header('content-type')); |
115
|
0
|
|
|
|
|
|
return $_response_object; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
# |
119
|
|
|
|
|
|
|
# GetRecognizeDocument |
120
|
|
|
|
|
|
|
# |
121
|
|
|
|
|
|
|
# Recognize image text, language and text region can be selected, default dictionaries can be used for correction. |
122
|
|
|
|
|
|
|
# |
123
|
|
|
|
|
|
|
# @param String $name Name of the file to recognize. (required) |
124
|
|
|
|
|
|
|
# @param String $language Language of the document. (optional) |
125
|
|
|
|
|
|
|
# @param String $rectX Top left point X coordinate of to recognize text inside. (optional) |
126
|
|
|
|
|
|
|
# @param String $rectY Top left point Y coordinate of to recognize text inside. (optional) |
127
|
|
|
|
|
|
|
# @param String $rectWidth Width of to recognize text inside. (optional) |
128
|
|
|
|
|
|
|
# @param String $rectHeight Height of to recognize text inside. (optional) |
129
|
|
|
|
|
|
|
# @param Boolean $useDefaultDictionaries Use default dictionaries for result correction. (optional) |
130
|
|
|
|
|
|
|
# @param String $storage Image's storage. (optional) |
131
|
|
|
|
|
|
|
# @param String $folder Image's folder. (optional) |
132
|
|
|
|
|
|
|
# @return OCRResponse |
133
|
|
|
|
|
|
|
# |
134
|
|
|
|
|
|
|
sub GetRecognizeDocument { |
135
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# verify the required parameter 'name' is set |
139
|
0
|
0
|
|
|
|
|
unless (exists $args{'name'}) { |
140
|
0
|
|
|
|
|
|
croak("Missing the required parameter 'name' when calling GetRecognizeDocument"); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# parse inputs |
145
|
0
|
|
|
|
|
|
my $_resource_path = '/ocr/{name}/recognize/?appSid={appSid}&language={language}&rectX={rectX}&rectY={rectY}&rectWidth={rectWidth}&rectHeight={rectHeight}&useDefaultDictionaries={useDefaultDictionaries}&storage={storage}&folder={folder}'; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q&\E/&/g; |
148
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q\/?\E/?/g; |
149
|
0
|
|
|
|
|
|
$_resource_path =~ s/\QtoFormat={toFormat}\E/format={format}/g; |
150
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{path}\E/{Path}/g; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $_method = 'GET'; |
153
|
0
|
|
|
|
|
|
my $query_params = {}; |
154
|
0
|
|
|
|
|
|
my $header_params = {}; |
155
|
0
|
|
|
|
|
|
my $form_params = {}; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# 'Accept' and 'Content-Type' header |
158
|
0
|
|
|
|
|
|
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json'); |
159
|
0
|
0
|
|
|
|
|
if ($_header_accept) { |
160
|
0
|
|
|
|
|
|
$header_params->{'Accept'} = $_header_accept; |
161
|
|
|
|
|
|
|
} |
162
|
0
|
|
|
|
|
|
$header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json'); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# query params |
165
|
0
|
0
|
|
|
|
|
if ( exists $args{'name'}) { |
166
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{name}\E/$args{'name'}/g; |
167
|
|
|
|
|
|
|
}else{ |
168
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]name.*?(?=&|\?|$)//g; |
169
|
|
|
|
|
|
|
}# query params |
170
|
0
|
0
|
|
|
|
|
if ( exists $args{'language'}) { |
171
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{language}\E/$args{'language'}/g; |
172
|
|
|
|
|
|
|
}else{ |
173
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]language.*?(?=&|\?|$)//g; |
174
|
|
|
|
|
|
|
}# query params |
175
|
0
|
0
|
|
|
|
|
if ( exists $args{'rectX'}) { |
176
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{rectX}\E/$args{'rectX'}/g; |
177
|
|
|
|
|
|
|
}else{ |
178
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]rectX.*?(?=&|\?|$)//g; |
179
|
|
|
|
|
|
|
}# query params |
180
|
0
|
0
|
|
|
|
|
if ( exists $args{'rectY'}) { |
181
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{rectY}\E/$args{'rectY'}/g; |
182
|
|
|
|
|
|
|
}else{ |
183
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]rectY.*?(?=&|\?|$)//g; |
184
|
|
|
|
|
|
|
}# query params |
185
|
0
|
0
|
|
|
|
|
if ( exists $args{'rectWidth'}) { |
186
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{rectWidth}\E/$args{'rectWidth'}/g; |
187
|
|
|
|
|
|
|
}else{ |
188
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]rectWidth.*?(?=&|\?|$)//g; |
189
|
|
|
|
|
|
|
}# query params |
190
|
0
|
0
|
|
|
|
|
if ( exists $args{'rectHeight'}) { |
191
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{rectHeight}\E/$args{'rectHeight'}/g; |
192
|
|
|
|
|
|
|
}else{ |
193
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]rectHeight.*?(?=&|\?|$)//g; |
194
|
|
|
|
|
|
|
}# query params |
195
|
0
|
0
|
|
|
|
|
if ( exists $args{'useDefaultDictionaries'}) { |
196
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{useDefaultDictionaries}\E/$args{'useDefaultDictionaries'}/g; |
197
|
|
|
|
|
|
|
}else{ |
198
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]useDefaultDictionaries.*?(?=&|\?|$)//g; |
199
|
|
|
|
|
|
|
}# query params |
200
|
0
|
0
|
|
|
|
|
if ( exists $args{'storage'}) { |
201
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{storage}\E/$args{'storage'}/g; |
202
|
|
|
|
|
|
|
}else{ |
203
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]storage.*?(?=&|\?|$)//g; |
204
|
|
|
|
|
|
|
}# query params |
205
|
0
|
0
|
|
|
|
|
if ( exists $args{'folder'}) { |
206
|
0
|
|
|
|
|
|
$_resource_path =~ s/\Q{folder}\E/$args{'folder'}/g; |
207
|
|
|
|
|
|
|
}else{ |
208
|
0
|
|
|
|
|
|
$_resource_path =~ s/[?&]folder.*?(?=&|\?|$)//g; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
my $_body_data; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# authentication setting, if any |
218
|
0
|
|
|
|
|
|
my $auth_settings = []; |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
# make the API Call |
221
|
0
|
|
|
|
|
|
my $response = $self->{api_client}->call_api($_resource_path, $_method, |
222
|
|
|
|
|
|
|
$query_params, $form_params, |
223
|
|
|
|
|
|
|
$header_params, $_body_data, $auth_settings); |
224
|
0
|
0
|
|
|
|
|
if (!$response) { |
225
|
0
|
|
|
|
|
|
return; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
0
|
0
|
|
|
|
|
if($AsposeOcrCloud::Configuration::debug){ |
229
|
0
|
|
|
|
|
|
print "\nResponse Content: ".$response->content; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
my $_response_object = $self->{api_client}->pre_deserialize($response->content, 'OCRResponse', $response->header('content-type')); |
233
|
0
|
|
|
|
|
|
return $_response_object; |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
1; |