@@ -36,14 +36,20 @@ static void Main(string[] args)
36
36
text = RecognizeFromStorage ( conf ) ;
37
37
Console . WriteLine ( "-------------\n " + text + "\n -------------\n " ) ;
38
38
39
- Console . WriteLine ( "Example #4:\n Recognize one of 21 supported languages" ) ;
39
+ Console . WriteLine ( "Example #4.1 :\n Recognize one of 21 supported languages" ) ;
40
40
text = RecognizeFromStorageDeFr ( conf ) ;
41
41
// You may also recognize it from Content or URL
42
42
//text = RecognizeFromContentDeFr(conf);
43
43
Console . WriteLine ( "-------------\n " + text + "\n -------------\n " +
44
44
"Attention: UTF is not supported in windows console." +
45
45
"\n ---------------------------------------------------\n " ) ;
46
46
47
+ Console . WriteLine ( "Example #4.2:\n Recognize Arabic" ) ;
48
+ text = RecognizeFromContentAr ( conf ) ;
49
+ Console . WriteLine ( "-------------\n " + text + "\n -------------\n " +
50
+ "Attention: UTF is not supported in windows console." +
51
+ "\n ---------------------------------------------------\n " ) ;
52
+
47
53
Console . WriteLine ( "Example #5:\n Recognize specific text regions (by coordinates) by URL" ) ;
48
54
text = RecognizeRegionsFromUrl ( conf ) ;
49
55
Console . WriteLine ( "-------------\n " + text + "\n -------------\n " +
@@ -89,7 +95,7 @@ static string RecognizeFromUrl(Configuration conf)
89
95
{
90
96
string imgUri = @"https://upload.wikimedia.org/wikipedia/commons/2/2f/Book_of_Abraham_FirstPage.png" ;
91
97
OcrApi api = new OcrApi ( conf ) ;
92
- var request = new PostOcrFromUrlOrContentRequest ( null , imgUri ) ;
98
+ var request = new PostOcrFromUrlOrContentRequest ( null , imgUri , resultType : ResultType . Text ) ;
93
99
OCRResponse response = api . PostOcrFromUrlOrContent ( request ) ;
94
100
95
101
return response . Text ;
@@ -135,6 +141,19 @@ static string RecognizeFromContentDeFr(Configuration conf)
135
141
return response . Text ;
136
142
}
137
143
}
144
+
145
+ static string RecognizeFromContentAr ( Configuration conf )
146
+ {
147
+ string name = "ar2.png" ;
148
+ using ( FileStream fs = File . OpenRead ( name ) )
149
+ {
150
+ OcrApi api = new OcrApi ( conf ) ;
151
+ var request = new PostOcrFromUrlOrContentRequest ( fs , "" , language : LanguageEnum . Arabic ) ;
152
+ OCRResponse response = api . PostOcrFromUrlOrContent ( request ) ;
153
+
154
+ return response . Text ;
155
+ }
156
+ }
138
157
139
158
static string RecognizeFromStorageDeFr ( Configuration conf )
140
159
{
@@ -183,22 +202,21 @@ static string RecognizeRegionsFromUrl(Configuration conf)
183
202
184
203
static string RecognizeRegionsFromContent ( Configuration conf )
185
204
{
186
- List < OCRRegion > mImageBook_of_Abraham_FirstPagePngRegions = new List < OCRRegion > ( )
205
+ List < OCRRegion > mImage5PngRegions = new List < OCRRegion > ( )
187
206
{
188
- new OCRRegion ( ) { Order = 0 , Rect = new OCRRect ( 209 , 28 , 283 , 39 ) } ,
189
- new OCRRegion ( ) { Order = 1 , Rect = new OCRRect ( 24 , 114 , 359 , 185 ) } ,
190
- new OCRRegion ( ) { Order = 2 , Rect = new OCRRect ( 21 , 201 , 356 , 451 ) } ,
191
- new OCRRegion ( ) { Order = 3 , Rect = new OCRRect ( 21 , 464 , 359 , 558 ) }
207
+ new OCRRegion ( ) { Order = 0 , Rect = new OCRRect ( 243 , 308 , 2095 , 964 ) } ,
208
+ new OCRRegion ( ) { Order = 1 , Rect = new OCRRect ( 240 , 1045 , 2108 , 1826 ) } ,
209
+ new OCRRegion ( ) { Order = 2 , Rect = new OCRRect ( 237 , 1916 , 2083 , 3180 ) }
192
210
} ;
193
211
194
- string name = "de_1.jpg " ;
212
+ string name = "5.png " ;
195
213
using ( FileStream fs = File . OpenRead ( name ) )
196
214
{
197
215
OcrApi api = new OcrApi ( conf ) ;
198
216
OCRRegionsRequestData requestData = new OCRRegionsRequestData ( )
199
217
{
200
- Language = LanguageEnum . German ,
201
- Regions = mImageBook_of_Abraham_FirstPagePngRegions
218
+ Language = LanguageEnum . English ,
219
+ Regions = mImage5PngRegions
202
220
} ;
203
221
OCRResponse response = api . OcrRegionsFromContent ( requestData , fs ) ;
204
222
@@ -208,15 +226,14 @@ static string RecognizeRegionsFromContent(Configuration conf)
208
226
209
227
static string RecognizeRegionsFromStorage ( Configuration conf )
210
228
{
211
- List < OCRRegion > mImageBook_of_Abraham_FirstPagePngRegions = new List < OCRRegion > ( )
229
+ List < OCRRegion > mImage5PngRegions = new List < OCRRegion > ( )
212
230
{
213
- new OCRRegion ( ) { Order = 0 , Rect = new OCRRect ( 209 , 28 , 283 , 39 ) } ,
214
- new OCRRegion ( ) { Order = 1 , Rect = new OCRRect ( 24 , 114 , 359 , 185 ) } ,
215
- new OCRRegion ( ) { Order = 2 , Rect = new OCRRect ( 21 , 201 , 356 , 451 ) } ,
216
- new OCRRegion ( ) { Order = 3 , Rect = new OCRRect ( 21 , 464 , 359 , 558 ) }
231
+ new OCRRegion ( ) { Order = 0 , Rect = new OCRRect ( 243 , 308 , 2095 , 964 ) } ,
232
+ new OCRRegion ( ) { Order = 1 , Rect = new OCRRect ( 240 , 1045 , 2108 , 1826 ) } ,
233
+ new OCRRegion ( ) { Order = 2 , Rect = new OCRRect ( 237 , 1916 , 2083 , 3180 ) }
217
234
} ;
218
235
219
- string name = "de_1.jpg " ;
236
+ string name = "5.png " ;
220
237
using ( FileStream fs = File . OpenRead ( name ) )
221
238
{
222
239
OcrApi api = new OcrApi ( conf ) ;
@@ -227,7 +244,7 @@ static string RecognizeRegionsFromStorage(Configuration conf)
227
244
OCRRegionsRequestDataStorage requestData = new OCRRegionsRequestDataStorage ( )
228
245
{
229
246
Language = LanguageEnum . German ,
230
- Regions = mImageBook_of_Abraham_FirstPagePngRegions ,
247
+ Regions = mImage5PngRegions ,
231
248
FileName = name
232
249
} ;
233
250
OCRResponse response = api . OcrRegionsFromContent ( requestData , fs ) ;
@@ -245,7 +262,7 @@ static string RecognizeFromContentToPdf(Configuration conf)
245
262
var request = new PostOcrFromUrlOrContentRequest ( fs , resultType : ResultType . Pdf , dsrMode : DsrMode . DsrAndFilter ) ;
246
263
OCRResponse response = api . PostOcrFromUrlOrContent ( request ) ;
247
264
248
- return response . Pdf ;
265
+ return response . Pdf . Substring ( 0 , 30 ) + " .................." ;
249
266
}
250
267
}
251
268
@@ -293,7 +310,7 @@ static string RecognizePdfFromContent(Configuration conf)
293
310
294
311
static string RecognizeTableFromContent ( Configuration conf )
295
312
{
296
- string name = "table.png " ;
313
+ string name = "table.jpeg " ;
297
314
using ( FileStream fs = File . OpenRead ( name ) )
298
315
{
299
316
OcrApi api = new OcrApi ( conf ) ;
@@ -307,7 +324,7 @@ static string RecognizeTableFromContent(Configuration conf)
307
324
308
325
static string RecognizeTableFromStorage ( Configuration conf )
309
326
{
310
- string name = "table.png " ;
327
+ string name = "table.jpeg " ;
311
328
using ( FileStream fs = File . OpenRead ( name ) )
312
329
{
313
330
OcrApi api = new OcrApi ( conf ) ;
0 commit comments