You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cognitive-services/Computer-vision/QuickStarts/CSharp-hand-text.md
+322-4Lines changed: 322 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: "Quickstart: Extract printed and handwritten text - REST, C#"
2
+
title: "Quickstart: Computer Vision 2.0 and 2.1 - Extract printed and handwritten text - REST, C#"
3
3
titleSuffix: "Azure Cognitive Services"
4
4
description: In this quickstart, you extract printed and handwritten text from an image using the Computer Vision API with C#.
5
5
services: cognitive-services
@@ -13,22 +13,41 @@ ms.date: 12/05/2019
13
13
ms.author: pafarley
14
14
ms.custom: seodec18
15
15
---
16
-
# Quickstart: Extract printed and handwritten text using the Computer Vision REST API and C#
16
+
# Quickstart: Extract printed and handwritten text using the Computer Vision 2.0 and 2.1 REST API and C#
17
17
18
18
In this quickstart, you will extract printed and/or handwritten text from an image using the Computer Vision REST API. With the [Batch Read](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/2afb498089f74080d7ef85eb) and [Read Operation Result](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/5be108e7498a4f9ed20bf96d) methods, you can detect text in an image and extract recognized characters into a machine-readable character stream. The API will determine which recognition model to use for each line of text, so it supports images with both printed and handwritten text.
19
19
20
+
Compared to Computer Vision 2.0 and 2.1, the Computer Vision 3.0 Public Preview provides:
21
+
22
+
* even better accuracy
23
+
* a changed output format
24
+
* confidence score for words
25
+
* support of both Spanish and English languages with the additional language parameter
26
+
27
+
#### [Version 2](#tab/version-2)
28
+
20
29
> [!IMPORTANT]
21
-
> The [Batch Read](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/2afb498089f74080d7ef85eb) method runs asynchronously. This method does not return any information in the body of a successful response. Instead, the Read method returns a URI in the `Operation-Location` response header field. You can then use this URI, which represents the [Read Operation Result](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/5be108e7498a4f9ed20bf96d) method, in order to check the status and return the results of the Batch Read method call.
30
+
> The [Batch Read](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/2afb498089f74080d7ef85eb) method runs asynchronously. This method does not return any information in the body of a successful response. Instead, the Batch Read method returns a URI in the value of the `Operation-Location` response header field. You can then call this URI, which represents the [Read Operation Result](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/5be108e7498a4f9ed20bf96d) API, to both check the status and return the results of the Batch Read method call.
31
+
32
+
#### [Version 3 (Public preview)](#tab/version-3)
33
+
34
+
> [!IMPORTANT]
35
+
> The [Batch Read](https://westus2.dev.cognitive.microsoft.com/docs/services/5d98695995feb7853f67d6a6/operations/5d986960601faab4bf452005) method runs asynchronously. This method does not return any information in the body of a successful response. Instead, the Batch Read method returns a URI in the value of the `Operation-Location` response header field. You can then call this URI, which represents the [Read Operation Result](https://westus2.dev.cognitive.microsoft.com/docs/services/5d98695995feb7853f67d6a6/operations/5d9869604be85dee480c8750) API, to both check the status and return the results of the Batch Read method call.
36
+
37
+
---
22
38
23
-
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/ai/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=cognitive-services) before you begin.
24
39
25
40
## Prerequisites
26
41
42
+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/ai/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=cognitive-services) before you begin.
43
+
27
44
- You must have [Visual Studio 2015 or later](https://visualstudio.microsoft.com/downloads/).
28
45
- You must have a subscription key for Computer Vision. You can get a free trial key from [Try Cognitive Services](https://azure.microsoft.com/try/cognitive-services/?api=computer-vision). Or, follow the instructions in [Create a Cognitive Services account](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account) to subscribe to Computer Vision and get your key. Then, [create environment variables](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account#configure-an-environment-variable-for-authentication) for the key and service endpoint string, named `COMPUTER_VISION_SUBSCRIPTION_KEY` and `COMPUTER_VISION_ENDPOINT`, respectively.
29
46
30
47
## Create and run the sample application
31
48
49
+
#### [Version 2](#tab/version-2)
50
+
32
51
To create the sample in Visual Studio, do the following steps:
33
52
34
53
1. Create a new Visual Studio solution in Visual Studio, using the Visual C# Console App template.
// Get the path and filename to process from the user.
260
+
Console.WriteLine("Cognitive Service Batch Read File Sample");
261
+
Console.WriteLine("Usage: ");
262
+
Console.WriteLine(" From Azure Cogntivie Service, retrieve your endpoint and subscription key.");
263
+
Console.WriteLine(" Set environment variable COMPUTER_VISION_ENDPOINT, such as \"https://westus2.api.cognitive.microsoft.com\"");
264
+
Console.WriteLine(" Set environment variable COMPUTER_VISION_SUBSCRIPTION_KEY, such as \"1234567890abcdef1234567890abcdef\"\n");
265
+
Console.WriteLine(" Run the program without argument to enter a file name and a language manually.");
266
+
Console.WriteLine(" Or run the program with a file name for an image file (bmp/jpg/png/tiff) or a PDF file, plus the language. The language can be \"en\" or \"es\".");
267
+
Console.WriteLine(" For example: dotnet Program.dll sample.jpg en");
268
+
Console.WriteLine();
269
+
}
270
+
271
+
staticvoidMain(string[] args)
272
+
{
273
+
PrintUsage();
274
+
275
+
if (string.IsNullOrEmpty(subscriptionKey) ||string.IsNullOrEmpty(endpoint))
276
+
{
277
+
Console.Error.WriteLine("Please set environment variables COMPUTER_VISION_ENDPOINT and COMPUTER_VISION_SUBSCRIPTION_KEY.");
278
+
return;
279
+
}
280
+
281
+
stringimageFilePath;
282
+
stringlanguage;
283
+
if (args.Length==0)
284
+
{
285
+
Console.Write(
286
+
"Enter the path to an image (bmp/jpg/png/tiff) or PDF with text you wish to read: ");
287
+
imageFilePath=Console.ReadLine();
288
+
}
289
+
else
290
+
{
291
+
imageFilePath=args[0];
292
+
}
293
+
294
+
if (args.Length<=1)
295
+
{
296
+
Console.Write(
297
+
"Enter the language to read: \"en\" or \"es\": ");
A successful response is returned in JSON. The sample application parses and displays a successful response in the console window, similar to the following example:
206
450
451
+
#### [Version 2](#tab/version-2)
452
+
207
453
```json
208
454
{
209
455
"status": "Succeeded",
@@ -304,6 +550,78 @@ A successful response is returned in JSON. The sample application parses and dis
304
550
}
305
551
```
306
552
553
+
#### [Version 3 (Public preview)](#tab/version-3)
554
+
555
+
556
+
```json
557
+
{
558
+
"status": "succeeded",
559
+
"createdDateTime": "2020-02-11T16:44:36Z",
560
+
"lastUpdatedDateTime": "2020-02-11T16:44:36Z",
561
+
"analyzeResult": {
562
+
"version": "3.0.0",
563
+
"readResults": [
564
+
{
565
+
"page": 1,
566
+
"language": "es",
567
+
"angle": -0.8011,
568
+
"width": 401,
569
+
"height": 119,
570
+
"unit": "pixel",
571
+
"lines": [
572
+
{
573
+
"language": "es",
574
+
"boundingBox": [
575
+
15,
576
+
42,
577
+
372,
578
+
38,
579
+
373,
580
+
91,
581
+
15,
582
+
97
583
+
],
584
+
"text": "¡Buenos días!",
585
+
"words": [
586
+
{
587
+
"boundingBox": [
588
+
15,
589
+
43,
590
+
243,
591
+
40,
592
+
244,
593
+
93,
594
+
17,
595
+
98
596
+
],
597
+
"text": "¡Buenos",
598
+
"confidence": 0.56
599
+
},
600
+
{
601
+
"boundingBox": [
602
+
254,
603
+
40,
604
+
370,
605
+
38,
606
+
371,
607
+
91,
608
+
255,
609
+
93
610
+
],
611
+
"text": "días!",
612
+
"confidence": 0.872
613
+
}
614
+
]
615
+
}
616
+
]
617
+
}
618
+
]
619
+
}
620
+
}
621
+
```
622
+
623
+
---
624
+
307
625
## Clean up resources
308
626
309
627
When no longer needed, delete the Visual Studio solution. To do so, open File Explorer, navigate to the folder in which you created the Visual Studio solution, and delete the folder.
0 commit comments