【问题标题】:Google OCR language hints谷歌 OCR 语言提示
【发布时间】:2017-11-23 14:29:32
【问题描述】:

这里的文档页面上说:https://cloud.google.com/vision/docs/ocr,您可以指定语言提示以帮助 OCR 更准确地检测图像中的文本。有谁知道我会在我的代码中在哪里指定语言提示?我正在使用 .net 控制台应用程序对其进行编程。

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

我似乎无法访问 ImageContext 类的语言提示属性,因为它是只读的。有没有办法创建一个可以指定语言提示的 ImageContext?

【问题讨论】:

    标签: google-cloud-platform ocr google-cloud-vision


    【解决方案1】:

    您可以使用以下方法创建 ImageContext 对象并在 AnnotateImageRequest 中设置它:

    // 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】:

      我遇到了同样的问题并解决了。 LanguageHints 是列表。您可以添加语言。当然你也可以添加多种语言。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多