谷歌云视觉api-OCR [英] Google cloud vision api- OCR

查看:107
本文介绍了谷歌云视觉api-OCR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用来自谷歌云视觉 API 的图像 (OCR) 的文本检测.但我不知道如何从 C# 中获取订阅密钥以及如何在 C# 中进行身份验证和调用.有人可以告诉我一步一步的程序来做到这一点.顺便说一句,我很新.

I want to use text-detection from image (OCR) of google cloud vision api. But i dont know how to get the subscription key from and how to authenticate and make calls in C#. Can some body tell me the step by step procedure to do that. Im very new this btw.

推荐答案

我觉得这个问题有点混乱,所以让我退后一步,尝试涵盖在使用 Cloud Vision API 时与身份验证有关的最重要的事情.

I think the question is a bit messed up, so let me take a step back and try to cover the most important things regarding authentication when using the Cloud Vision API.

首先,该文档对如何向 Cloud Vision 进行身份验证提供了非常清晰的解释API,使用 API 密钥或服务帐户.请记住,如 Google Cloud Platform 中的身份验证最佳做法中所述:

First of all, the documentation offers a really clear explanation on how to authenticate to the Cloud Vision API, using API keys or Service Accounts. Bear in mind that, as documented in the best practices for authentication in the Google Cloud Platform:

对于几乎所有情况,无论您是在本地开发还是在生产应用程序,您应该使用服务帐户,而不是用户帐户或 API 密钥.

For almost all cases, whether you are developing locally or in a production application, you should use service accounts, rather than user accounts or API keys.

明确这一点后,使用 API 密钥(我理解这就是您提到订阅密钥"时所指的)或服务帐户显然取决于您.以下是这两种身份验证方法可能与您相关的主要区别:

Being this clarified, it is obviously up to you whether to use API keys (I understand this is what you refer to when you mention "subscription keys") or Service Accounts. Here are the main differences that may be relevant for you regarding these two authentication methods:

  • 服务帐户:它们更安全,是推荐的使用方法,并且可以与 API 客户端库轻松轻松地集成,这让您在与 GCP API 交互时更加轻松.我强烈建议您使用服务帐户和惯用的客户端库.
  • API 密钥:您应该遵循一组 安全使用它们的最佳实践,并且它们不能(或者至少我不知道)与客户端库集成;因此,您需要直接调用 REST API,这比使用惯用的客户端库更复杂.
  • Service Accounts: they are more secure, the recommended approach to use, and integrate well and easily with the APIs Client Libraries, which make your life much easier when it comes to interacting with GCP APIs. I strongly recommend you to use Service Accounts and idiomatic Client Libraries.
  • API keys: you should follow a set of best practices for securely using them, and they cannot (or at least I am not aware of that) integrate with the Client Libraries; therefore you will need to make calls to the REST API directly, which is more complex than using idiomatic Client Libraries.

我希望我已经能够强调可用的替代身份验证方法之间的差异.那么让我们继续下一个主题,验证请求:

I hope I have been able to highlight the differences between the alternative authentication methods available. So let's move on to the next topic, authenticating requests:

如果您使用 API 密钥,只需将 API 密钥附加到 REST API 方法,就像这样:

If you are using API keys, it is as easy as as appending the API key to the REST API method that you want to call, just like this:

https://vision.googleapis.com/v1/images:annotate?key=YOUR_API_KEY

在这种情况下,您将不得不想办法在 C# 中发出 HTTP 请求、解析 JSON 响应等.

In such a case, you will have to find a way to make HTTP requests in C#, parse the JSON response, etc.

如果您使用的是服务帐户(我希望我在回答的第一部分说服了您这样做),您需要关注 文档中详述了这些步骤:

If you are using Service Accounts (I hope I convinced you to do so in the first part of my answer), you will need to follow these steps detailed in the documentation:

  1. 为您的服务帐户下载 JSON 密钥.
  2. 在您机器的 GOOGLE_APPLICATION_CREDENTIALS 环境变量中引用它.
  3. 按照这个简单示例中的说明使用 C# 客户端库,或使用完整的文档参考来获取有关如何使用此库的所有详细信息 (客户端库文档ImageAnnotatorClient 文档).
  1. Download the JSON key for your Service Account.
  2. Refer to it in the GOOGLE_APPLICATION_CREDENTIALS environment variable in your machine.
  3. Use the C# Client Libraries as explained in this simple example, or use the complete documentation reference to have all the details about how to use this library (Client Library documentation and ImageAnnotatorClient documentation).

这篇关于谷歌云视觉api-OCR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆