zoukankan      html  css  js  c++  java
  • Azure 认知服务 (5) 计算机视觉API

      《Windows Azure Platform 系列文章目录

      在笔者之前的文章:Azure 认知服务 (4) 计算机视觉API - 读取图片中的文字 (OCR)

      介绍了使用用户界面,在海外的Windows Azure认知服务的读取图片功能。

      在本章,笔者会介绍如何通过国内由世纪互联运维的Azure China,使用C#代码,实现实现读取图片中的文字(OCR)功能。  

      

      我们需要准备:

      1.Azure China账户

      2.计算机视觉API的API Key

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

      我们现在开始正文

      1.我们可以访问:https://dev.cognitive.azure.cn/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fc

      可以看到最下面提供不同的开发语言Code Sample

      

      2.我们复制出C# Code,这是一个Windows Console

      根据注释的内容,修改变量

      (1) API Key

      (2) JPG图片URL

      代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;
    using System.Net.Http.Headers;
    using System.Web;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            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", "{subscription key}");
    
                // Request parameters
                queryString["language"] = "unk";
                queryString["detectOrientation "] = "true";
                var uri = "https://api.cognitive.azure.cn/vision/v1.0/ocr?" + queryString;
    
                HttpResponseMessage response;
    
                // 这里输入使用的jpg图片路径
                string s = @"{""url"":" + @"""https://leizhangstorage.blob.core.chinacloudapi.cn/azureblog/ocr.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();
                }
            }
        }
    }

      

  • 相关阅读:
    Linux:Day45(下)
    Linux:Day45(上)
    Linux:Day44(下)
    彻底理解JDK异步
    Ribbon是什么?
    RocketMQ学习笔记(一)eclipse版的quickstart
    线性表的遍历
    八皇后问题
    汉诺塔
    servlet的url-pattern规则
  • 原文地址:https://www.cnblogs.com/threestone/p/7267764.html
Copyright © 2011-2022 走看看