//百度图片识别api接口
public static JObject GeneralBasic(string apikey,string secretkey,string path)
{
var client = new Baidu.Aip.Ocr.Ocr(apikey, secretkey);
var image = File.ReadAllBytes(path);
// 通用文字识别
var result = client.GeneralBasic(image, null);
return result;
}
//挪用,要领,以及返回json 解析
private void txbupload_Click(object sender, EventArgs e)
{
string apikey = txbapikey.Text;
string secretkey = txbsercetkey.Text;
string imagepath = txbpic.Text+ "\\yancaoxuke.jpg";
JObject result = OcrDemo.GeneralBasic(apikey, secretkey, imagepath);
var txts = (from obj in (JArray)result.Root["words_result"]
// let phrase = (JObject)obj["phrase"]
select (string)obj["words"]);
foreach (var r in txts)
Console.WriteLine(r);
}
//包布局
log_id:3544105182,words_result_num:15,words_result:[
{
"words": "XX专卖零售许可证"
},
{
"words": "许可证号xxx"
},
{
"words": "XX有限公司"
},
{
"words": "法定代表人xx"
},
{
"words": "(卖力人)"
},
{
"words": "320507217865"
},
{
"words": "企业型"
},
{
"words": "有限责任公司"
},
{
"words": "经營场xx室"
},
{
"words": "卷烟,雪茄烟"
},
{
"words": "许可范畴"
},
{
"words": "xxxx公司"
},
{
"words": "供货单位"
},
{
"words": "有效期服自"
},
DEMO1
const string s = "{\"result\" : \"ok\",\"tuc\" : [ {\"authors\" : [ 13 ],\"meaningId\" : 2397164096556578585,\"phrase\" : {\"text\" : \"机场\",\"language\" : \"zho\" }},{\"authors\" : [ 3266 ],\"meaningId\" : 1269040436618011315,\"phrase\" : {\"text\" : \"機場\",\"language\" : \"zho\"}}]}";
var root = JObject.Parse(s);
var txts = (from obj in (JArray)root["tuc"]
let phrase = (JObject)obj["phrase"]
select (string)phrase["text"]);
foreach (var r in txts)
Console.WriteLine(r);
DEMO2
const string s = "{\"result\" : \"ok\",\"tuc\" : [ {\"authors\" : [ 13 ],\"meaningId\" : 2397164096556578585,\"phrase\" : {\"text\" : \"机场\",\"language\" : \"zho\" }},{\"authors\" : [ 3266 ],\"meaningId\" : 1269040436618011315,\"phrase\" : {\"text\" : \"機場\",\"language\" : \"zho\"}}]}";
var root = JObject.Parse(s);
var txts = (from obj in (JArray)root["tuc"]
select (string)obj["phrase"]["text"]);
foreach (var r in txts)
Console.WriteLine(r);