Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vision/api/Detect/Detect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PackageReference Include="Google.Cloud.Vision.V1" Version="1.6.0" />
<PackageReference Include="CommandLineParser" Version="2.3.0" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="2.3.0" />
<PackageReference Include="Google.Api.Gax.Grpc" Version="2.10.0" />
</ItemGroup>
<ItemGroup>
<None Remove="HelloWorld.exe" />
Expand Down
30 changes: 27 additions & 3 deletions vision/api/Detect/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
using System.Linq;
using System.IO;
using Google.Protobuf;

using Google.Api.Gax.Grpc;

namespace GoogleCloudSamples
{
class ImageOptions
Expand Down Expand Up @@ -48,7 +49,11 @@ class DetectFacesOptions : ImageOptions { }
class DetectLandmarksOptions : ImageOptions { }

[Verb("text", HelpText = "Detect text.")]
class DetectTextOptions : ImageOptions { }
class DetectTextOptions : ImageOptions
{
[Option('m', HelpText = "Uses multi-region endpoint")]
public bool EnableMultiRegion { get; set; }
}

[Verb("logos", HelpText = "Detect logos.")]
class DetectLogosOptions : ImageOptions { }
Expand Down Expand Up @@ -251,6 +256,23 @@ private static object DetectText(Image image)
return 0;
}

private static object DetectTextWithLocation(Image image)
{
// [START vision_set_endpoint]
// Instantiate a client connected to the 'eu' location.
var client = new ImageAnnotatorClientBuilder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove the (), they are not needed on object initializers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not know that! Thank you.

{
Endpoint = new ServiceEndpoint("eu-vision.googleapis.com")
}.Build();
// [END vision_set_endpoint]
var response = client.DetectText(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
Console.WriteLine(annotation.Description);
}
return 0;
}

private static object DetectLogos(Image image)
{
Expand Down Expand Up @@ -472,7 +494,9 @@ public static void Main(string[] args)
(DetectPropertiesOptions opts) => DetectProperties(ImageFromArg(opts.FilePath)),
(DetectFacesOptions opts) => DetectFaces(ImageFromArg(opts.FilePath)),
(DetectLandmarksOptions opts) => DetectLandmarks(ImageFromArg(opts.FilePath)),
(DetectTextOptions opts) => DetectText(ImageFromArg(opts.FilePath)),
(DetectTextOptions opts) => opts.EnableMultiRegion ?
DetectTextWithLocation(ImageFromArg(opts.FilePath))
: DetectText(ImageFromArg(opts.FilePath)),
(DetectLogosOptions opts) => DetectLogos(ImageFromArg(opts.FilePath)),
(DetectCropHintOptions opts) => DetectCropHint(ImageFromArg(opts.FilePath)),
(DetectWebOptions opts) => DetectWeb(ImageFromArg(opts.FilePath)),
Expand Down
8 changes: 8 additions & 0 deletions vision/api/VisionTest/VisionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ public void DetectText()
Assert.Contains("fermented", output.Stdout);
}

[Fact]
public void DetectTextWithMultiRegion()
{
var output = Run("text", Path.Combine("data", "bonito.gif"), "-m");
Assert.Equal(0, output.ExitCode);
Assert.Contains("fermented", output.Stdout);
}

[Fact]
public void DetectNoText()
{
Expand Down