Google OCR language hints

青春壹個敷衍的年華 提交于 2020-01-30 09:09:10

问题


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?


回答1:


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();



回答2:


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");


来源:https://stackoverflow.com/questions/47457788/google-ocr-language-hints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!