《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
我们现在开始正文
可以看到最下面提供不同的开发语言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(); } } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2014-08-02 Windows Azure Active Directory (1) 前言 - 基于声明的验证和授权
2013-08-02 [New Portal]Windows Azure Virtual Machine (19) 关闭Azure Virtual Machine与VIP Address,Internal IP Address的关系(1)