c#圖文識別之百度api調用

來源:互聯網
上載者:User

標籤:jpg   gid   ike   bapi   read   百度api   string   console   圖片   

//百度圖片識別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);

c#圖文識別之百度api調用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.