Azure 辨識服務 (3) 電腦視覺API - 分析映像,使用C#代碼

來源:互聯網
上載者:User

標籤:dev   tags   控制   service   json   圖片路徑   hive   一個   title   

  《Windows Azure Platform 系列文章目錄》

 

  在上一節中Azure 辨識服務 (2) 電腦視覺API - 分析映像,筆者介紹了如何使用API測試控制台進行調試。

  本章將介紹如何使用C#代碼調用分析映像功能。

 

  我們需要準備:

  1.Azure China賬戶

  2.電腦視覺API的API Key

  3.分析的圖片URL:https://leizhangstorage.blob.core.chinacloudapi.cn/azureblog/analyzeimagesample.jpg

  

  現在開始本文:

  1.我們可以訪問:https://dev.cognitive.azure.cn/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fa

  可以看到最下面提供不同的開發語言Code Sample:

  

  2.我們複製出C# Code,這是一個Windows Console

  根據注釋的內容,修改變數

  (1) API Key

  (2) JPG圖片URL

  代碼如下:

        static void Main(string[] args)        {            MakeRequest();            Console.WriteLine("Hit ENTER to exit...");            Console.ReadLine();        }        static async void MakeRequest()        {            var client = new HttpClient();            var queryString = HttpUtility.ParseQueryString(string.Empty);            // Request headers            // 這裡輸入API Key            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{API key}");            // Request parameters            // 這裡輸入visual Features            queryString["visualFeatures"] = "Categories,Tags,Description,Faces,ImageType,Color,Adult";            queryString["details"] = "";            queryString["language"] = "en";            var uri = "https://api.cognitive.azure.cn/vision/v1.0/analyze?" + queryString;            HttpResponseMessage response;            // 這裡輸入使用的jpg圖片路徑            string s = @"{""url"":" + @"""https://leizhangstorage.blob.core.chinacloudapi.cn/azureblog/analyzeimagesample.jpg""}";            // Request body            byte[] byteData = Encoding.UTF8.GetBytes(s);            using (var content = new ByteArrayContent(byteData))            {                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");                response = await client.PostAsync(uri, content);                var contents = await response.Content.ReadAsStringAsync();                  }        }

 

Azure 辨識服務 (3) 電腦視覺API - 分析映像,使用C#代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.