Skip to content

Commit da6156b

Browse files
authored
Update CSharp-hand-text.md
1 parent 00f5dfb commit da6156b

File tree

1 file changed

+22
-81
lines changed

1 file changed

+22
-81
lines changed

articles/cognitive-services/Computer-vision/QuickStarts/CSharp-hand-text.md

Lines changed: 22 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Quickstart: Computer Vision 2.0 and 2.1 - Extract printed and handwritten text - REST, C#"
2+
title: "Quickstart: Computer Vision 2.1, and 3.0 - Extract printed and handwritten text - REST, C#"
33
titleSuffix: "Azure Cognitive Services"
44
description: In this quickstart, you extract printed and handwritten text from an image using the Computer Vision API with C#.
55
services: cognitive-services
@@ -13,11 +13,11 @@ ms.date: 04/14/2020
1313
ms.author: pafarley
1414
ms.custom: seodec18
1515
---
16-
# Quickstart: Extract printed and handwritten text using the Computer Vision 2.0 and 2.1 REST API and C#
16+
# Quickstart: Extract printed and handwritten text using the Computer Vision 2.1 and 3.0 REST API and C#
1717

1818
In this quickstart, you'll 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.
1919

20-
Compared to Computer Vision 2.0 and 2.1, the Computer Vision 3.0 Public Preview provides:
20+
Compared to Computer Vision 2.1 and 3.0, the Computer Vision 3.0 Public Preview provides:
2121

2222
* even better accuracy
2323
* a changed output format
@@ -29,7 +29,7 @@ Compared to Computer Vision 2.0 and 2.1, the Computer Vision 3.0 Public Preview
2929
> [!IMPORTANT]
3030
> 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.
3131
32-
#### [Version 3 (Public preview)](#tab/version-3)
32+
#### [Version 3](#tab/version-3)
3333

3434
> [!IMPORTANT]
3535
> 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.
@@ -75,29 +75,20 @@ namespace CSHttpClientSample
7575
static string subscriptionKey = Environment.GetEnvironmentVariable("COMPUTER_VISION_SUBSCRIPTION_KEY");
7676

7777
static string endpoint = Environment.GetEnvironmentVariable("COMPUTER_VISION_ENDPOINT");
78-
78+
7979
// the Batch Read method endpoint
8080
static string uriBase = endpoint + "vision/v2.1/read/core/asyncBatchAnalyze";
81+
// Add your own local image with text (png or jpg OK)
82+
static string imageFilePath = @"my-image.png";
8183

82-
static async Task Main()
84+
static void Main()
8385
{
84-
// Get the path and filename to process from the user.
85-
Console.WriteLine("Text Recognition:");
86-
Console.Write(
87-
"Enter the path to an image with text you wish to read: ");
88-
string imageFilePath = Console.ReadLine();
8986

90-
if (File.Exists(imageFilePath))
91-
{
92-
// Call the REST API method.
93-
Console.WriteLine("\nWait a moment for the results to appear.\n");
94-
await ReadText(imageFilePath);
95-
}
96-
else
97-
{
98-
Console.WriteLine("\nInvalid file path");
99-
}
100-
Console.WriteLine("\nPress Enter to exit...");
87+
// Call the REST API method.
88+
Console.WriteLine("\nExtracting text...\n");
89+
ReadText(imageFilePath).Wait();
90+
91+
Console.WriteLine("\nPress Enter to exit.");
10192
Console.ReadLine();
10293
}
10394

@@ -252,70 +243,20 @@ namespace CSHttpClientSample
252243
static string endpoint = Environment.GetEnvironmentVariable("COMPUTER_VISION_ENDPOINT");
253244

254245
// the Batch Read method endpoint
255-
static string uriBase = endpoint + "/vision/v3.0-preview/read/analyze";
246+
static string uriBase = endpoint + "/vision/v3.0-preview//read/analyze";
247+
248+
// Add a local image with text here (png or jpg is OK)
249+
static string imageFilePath = @"my-image.png";
250+
// Add a language, either "en" or "es"
251+
static string language = "en";
256252

257-
static void PrintUsage()
258-
{
259-
// 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-
}
270253

271254
static void Main(string[] args)
272255
{
273-
PrintUsage();
256+
// Call the REST API method.
257+
Console.WriteLine("\nExtracting text...\n");
258+
ReadText(imageFilePath, language).Wait();
274259

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-
string imageFilePath;
282-
string language;
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\": ");
298-
language = Console.ReadLine();
299-
}
300-
else
301-
{
302-
language = args[1];
303-
}
304-
305-
Console.WriteLine($"Endpoint: [{endpoint}]");
306-
Console.WriteLine($"Subscription: [{subscriptionKey}]");
307-
Console.WriteLine($"URL: [{uriBase}]");
308-
309-
if (File.Exists(imageFilePath))
310-
{
311-
// Call the REST API method.
312-
Console.WriteLine("\nWait a moment for the results to appear.\n");
313-
ReadText(imageFilePath, language).Wait();
314-
}
315-
else
316-
{
317-
Console.WriteLine("\nInvalid file path");
318-
}
319260
Console.WriteLine("\nPress Enter to exit...");
320261
Console.ReadLine();
321262
}

0 commit comments

Comments
 (0)