Azure Cognitive Services (3) Computer Vision API-Analyze images using C # code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.