Windows Azure Platform Family of articles Catalog
In the previous section of Azure Cognitive Services (2) Computer Vision API-analyzing images , the author describes how to use the API test console for debugging.
This chapter describes how to call the Analyze image feature using C # code.
We need to prepare:
1.Azure China Account
2. API Key for the computer Vision API
3. Analysis of the picture url:https://leizhangstorage.blob.core.chinacloudapi.cn/azureblog/analyzeimagesample.jpg
Now start the text:
1. We have access to: HTTPS://DEV.COGNITIVE.AZURE.CN/DOCS/SERVICES/56F91F2D778DAF23D8EC6739/OPERATIONS/56F91F2E778DAF14A499E1FA
You can see that the following code Sample is available in different development languages:
2. We copied C # Code, which is a Windows Console
Modify variables according to the contents of the comment
(1) API Key
(2) JPG image URL
The code is as follows:
Static voidMain (string[] args) {makerequest (); Console.WriteLine ("Hit ENTER to exit ..."); Console.ReadLine (); } Static Async voidmakerequest () {varClient =NewHttpClient (); varqueryString = httputility.parsequerystring (string. Empty); //Request Headers//Enter the API Key hereClient. Defaultrequestheaders.add ("Ocp-apim-subscription-key","{API Key}"); //Request Parameters//Enter visual Features herequerystring["Visualfeatures"] ="Categories,tags,description,faces,imagetype,color,adult"; querystring["Details"] =""; querystring["language"] ="en"; varURI ="https://api.cognitive.azure.cn/vision/v1.0/analyze?"+queryString; Httpresponsemessage response; //Enter the JPG image path used here strings =@"{"url" ":"+@""" Https://leizhangstorage.blob.core.chinacloudapi.cn/azureblog/analyzeimagesample.jpg "" }"; //Request Body byte[] Bytedata =Encoding.UTF8.GetBytes (s); using(varContent =Newbytearraycontent (bytedata)) {content. Headers.contenttype=NewMediatypeheadervalue ("Application/json"); Response=awaitclient. Postasync (URI, content); varContents =awaitResponse. Content.readasstringasync (); } }
Azure Cognitive Services (3) Computer Vision API-Analyze images using C # code