1 前期准备
- Azure China 账户
- 计算机视觉 API 的 API Key
- 需要进行分析图片的 URL
2 操作开始
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.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-Subion-Key", "{subion 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();
			}
		}
	}
}
文章末尾固定信息

我的微信
我的微信
一个码农、工程狮、集能量和智慧于一身的、DIY高手、小伙伴er很多的、80后奶爸。



 服务器0元试用,首购低至0.9元/月起
服务器0元试用,首购低至0.9元/月起




评论