共用方式為


Setting up the Project

In Visual Studios click on File | New | Project

2018-03-19 (2)

In the New Project window Select Visual C# | Console App (.Net Framework)

image

For Name , you can leave as Default or name it something that reflects the Project you are going to write. unless you wish to change the location for this project leave the default value and verify Create directory for solution is checked. You can select the Add to Source Control if your Visual Studios is connected to TFS or GIT Hub.

image

Once you click on Ok the initial Project will setup and Load.

At first you should only see the following bit of code which includes 5 using statements. Notice the namespace in this particular project says “ComputerVisionMetaData” , What ever you put as the Name of the project will show up here.

image

Add the following using statements

using System.IO;

using System.Net.Http;

Your Code should now look like

image

Now lets add some Variables which we will use throughout our projects.

Just under Class Program and the 1st Brace add the following:

const string skey = " ";

const string uriBase = "https://westus.api.cognitive.microsoft.com/vision/v1.0/";

const string apiMethod =  " ";

const string fileSource = @"C:\Users\Pictures\"; // Source Location of Test Image

 

The Code should now look like

The Variable skey will be the Key you get from Managed Keys within the API you are going to access with this project. In more complex projects you will have multiple variables set depending on how many different Cognitive Services API’s you need to access.

For Review at this point your code should look something like the above image, Snippet of code will be used for a few of the projects that we will walk through in this blog.

We added a few Constant Variables which will be used as well.

  • SKEY
    • Is the variable that will be used to pass in the Key associated with the Specific Cognitive Services API this project will be working with.
  • uriBase
    • Is the variable that will be used to pass in the Endpoint of the API that you are going to access with this project.
  • apiMethod
    • Is the Method which gets appended to the uriBase, that when get put together with the rest of the "requestParameters" to form the Request URL. For more information on understanding and building the Request URL please visit the Vision API Reference.
  • fileSource
    • Is going to be used to define the path of the file (image, video, etc) that we are going to submit to the Cognitive Services API.

In the Next Post we will continue to build out the initial project which will get used several times on this Blog Site.