下载百度SDK https://ai.baidu.com/sdk
using Baidu.Aip.Ocr;
using Newtonsoft.Json.Linq;
using System.IO;
//图像文字识别
string apiKey = "MGjRWMPFMFY8Iu1GGox95BWC";//根据自己申请的key
string secretKey = "Nar5gtUdNe4aHs9Q0XUswG9fnqh79R5P";//根据自己申请的key
Ocr client = new Ocr(apiKey, secretKey)
{
Timeout = 30000//延时时间
};
byte[] image = File.ReadAllBytes(@"image\5.jpg");//需要识别的图片路径
JObject result = client.GeneralBasic(image);//json数据,具体格式可以看官方API说明
Console.WriteLine(result);
//以下是json Linq方式
//var res = from p in result["words_result"].Children()
// select new
// {
// words = (string)p["words"]
// };
////var result = client.WebImage(image);
//for (int i = 0; i < res.ToArray().Count() - 1;i++ )
//{
// Console.WriteLine(res.ToArray()[i].ToString());
// // Console.WriteLine(res..ToString());
//}
Console.ReadKey();