Enryu
Enryu

Reputation: 1424

Google OCR language hints

It says on the documentation page here: https://cloud.google.com/vision/docs/ocr that you can specify language hints to help OCR more accurately detect text in the image. Does anyone know where I would specify a language hint in my code? I am programming it using a .net console application.

using Google.Cloud.Vision.V1;
using System;

namespace GoogleCloudSamples
{
    public class QuickStart
    {
        public static void Main(string[] args)
        {
            // Instantiates a client
            var client = ImageAnnotatorClient.Create();
            // Load the image file into memory
            var image = Image.FromFile("wakeupcat.jpg");
            // Performs label detection on the image file
            var response = client.DetectLabels(image);
            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                    Console.WriteLine(annotation.Description);
            }
        }
    }
}

I can't seem to access the language hints property of the ImageContext class because it is read only. Is there a way to create an ImageContext where I can specify the language hints?

Upvotes: 2

Views: 2994

Answers (2)

Joongjin Bae
Joongjin Bae

Reputation: 29

I had same problem and solved it. LanguageHints is List. You can add language. Of course you can add multiple languages also.

ImageContext imageContext = new ImageContext();
imageContext.LanguageHints.Add("en");
imageContext.LanguageHints.Add("ko");

Upvotes: 2

t6nand
t6nand

Reputation: 780

You can create ImageContext object & set it in your AnnotateImageRequest using:

// Build ImageContext object
ImageContext imageContext = ImageContext.newBuilder().addLanguageHints("en").build();

// Set it to AnnotateImageRequest
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).setImageContext(imageContext).build();

Upvotes: 2

Related Questions