找到解决方案里的引用目录,右键,选择第一个添加引用。然后找到COM项目下的类型库。选择Microsoft Word 12.0 Object Library,点击浏览,在文件夹里找到下载的C#JDK里的两个.dll文件,选中上传即可。
using Baidu.Aip.Ocr;using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasksnamespace bauduyuntext1{ class baiduyunProgram { static void Main(string[] args) { // 设置APPID/AK/SK //var APP_ID = "你自己的"; var API_KEY = "你自己的"; var SECRET_KEY = "你自己的"; var client = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY); client.Timeout = 60000; // 修改超时时间 baiduyunProgram bai = new baiduyunProgram(); // bai.GeneralBasicUrlDemo(client); //图片URL地址调用 bai.GeneralBasicDemo(client); //图片本地地址调用 } public void GeneralBasicDemo(Ocr client) { var image = File.ReadAllBytes("D://112.jpg"); // 调用通用文字识别, 图片参数为本地图片,可能会抛出网络等异常,请使用try/catch捕获 var result = client.GeneralBasic(image); Console.WriteLine(result); // 如果有可选参数 var options = new Dictionary<string, object>{ {"language_type", "CHN_ENG"}, {"detect_direction", "true"}, {"detect_language", "true"}, {"probability", "true"} }; // 带参数调用通用文字识别, 图片参数为本地图片 result = client.GeneralBasic(image, options); Console.WriteLine(result); Console.Read(); } public void GeneralBasicUrlDemo(Ocr client) { var url = "http://p0.so.qhimgs1.com/bdr/_240_/t017cab315ee6c04600.jpg"; // 调用通用文字识别, 图片参数为远程url图片,可能会抛出网络等异常,请使用try/catch捕获 var result = client.GeneralBasicUrl(url); Console.WriteLine(result); // 如果有可选参数 var options = new Dictionary<string, object>{ {"language_type", "CHN_ENG"}, {"detect_direction", "true"}, {"detect_language", "true"}, {"probability", "true"} }; // 带参数调用通用文字识别, 图片参数为远程url图片 result = client.GeneralBasicUrl(url, options); Console.WriteLine(result); Console.Read(); } }}