Google cloud vision api- OCR

跟風遠走 提交于 2021-02-08 11:22:40

问题


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.


回答1:


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.

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:

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.

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:

  • 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:

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

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. 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).


来源:https://stackoverflow.com/questions/49665196/google-cloud-vision-api-ocr

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