【问题标题】:Detect Text in PDF/TIFF Files with Google Cloud Vision使用 Google Cloud Vision 检测 PDF/TIFF 文件中的文本
【发布时间】:2018-09-26 07:16:46
【问题描述】:

我想使用 Google Cloud Vision 检测 PDF 和 TIFF 文件中的文本,但从外观上看,只有先将文件存储到 Google Cloud Storage 才能完成。不存储在云端也能做到这一点吗?

【问题讨论】:

    标签: c# google-cloud-vision


    【解决方案1】:

    目前,您需要将内容存储在 Google Cloud Storage Bucket 中。但是,有一个feature request 可以读取 PDF 文件,而不必存储在存储桶中。我建议starring 这个问题并发表评论以表明这可以帮助您解决当前的情况。

    【讨论】:

    • 感谢您提出功能请求。我已加注星标
    【解决方案2】:

    如果您有图片(没有尝试过 PDF,您可能需要将其覆盖到图片中),您可以将其转换为 base 64 并发送..

    一些代码sn-ps:

    // 主要缩写代码-----

    var cloudVisionUrl = $"{annotationTextApiUrl}{annotationTextApiKey}";
    
                var imageBase64 = DoYourOwnImageToBase64(path);
    
                var client = new HttpClient();
    
                var requests = new ApiRequest { Requests = new List<Request> { new Request { Image = new Image {Content = imageBase64}, Features = new List<Feature> {new Feature {Type = "TEXT_DETECTION"}} } } };
    
                var httpResponse = await client.PostAsJsonAsync(cloudVisionUrl, requests);
    

    // -----------------------------------------

    public class ApiRequest
        {
            public ApiRequest()
            {
                Requests = new List<Request>();
            }
    
            [JsonProperty("requests")]
            public List<Request> Requests { get; set; }
        }
    
    public class Request
        {
            [JsonProperty("image")]
            public Image Image { get; set; }
    
            [JsonProperty("features")]
            public List<Feature> Features { get; set; }
        }
    
    public class Feature
        {
            [JsonProperty("type")]
            public string Type { get; set; }
        }
    

    【讨论】:

      【解决方案3】:

      现在是possible。只需将您的文件转换为 base64 并将其放入您的 inputConfig 的内容中。支持的格式为 PDF、gif 和 tiff。

      【讨论】:

        猜你喜欢
        • 2019-02-19
        • 2017-10-20
        • 1970-01-01
        • 2019-02-05
        • 1970-01-01
        • 1970-01-01
        • 2019-10-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多