
批處理混編javascript獲取在線圖片網址百度文字識別高精度OCR最后由 kaze 于 -4-2 13:32大家可以參照此帖看看百度ocr的要求等詳細解釋,http://www.bathome.net/viewthread.php?tid=48390&highlight=ocr但是本代碼并非來源于以上貼子,有心人肯定能夠猜到本代碼是干啥的了,但是是屬于不能明說的一類了。(這里的網址隱藏了真實意圖)源代碼并非批處理,也是用的百度普通ocr,現在提出要求,使用百度ocr高精度識別,把在線圖片base64編碼、去掉編碼頭后再進行urlencode。這一步我是怎么也搞不定了,希望有興趣的高手能夠實現,謝謝。
nclick="copycode($('code0'));">復制代碼
- var fso=new ActiveXObject('scripting.FileSystemObject');
- var http=new ActiveXObject('MSXML2.XMLHTTP');
- var m=0;
- var img_url_list='';
- var img_url_list=gettext('http://open.iciba.com/dsapi/').match(/fenxiang_img:(http.+)}/m)[1].replace(//g,'');
- var num=img_url_list.match(/d{4}(-dd){2}/m)[0];
- var client_id=你的百度文字識別的id;
- var client_secret=你的百度文字識別的Secret Key;
- var access_token=get_access_token(client_id,client_secret);
- var list=send_Pic2word_request(img_url_list,access_token);
- WSH.echo(num+'rn'+img_url_list+'rn'+list);
- //var f=fso.CreateTextFile('X:/ssr.txt', 2, true);
- //f.Write(num+'rn'+list);
- //f.Close();
- WSH.Quit();
- function gettext(url){
- var text='';
- http.open('Get', url, false)
- http.send();
- if (http.status == 200 ) {text=http.responseText;
- return text;}
- else {m++;WSH.echo(m);
- gettext(url);
- }
- }
- function get_access_token(client_id,client_secret){
- host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id='+client_id+'&client_secret='+client_secret
- http.open('Post', host, false)
- http.send();
- if (http.status == 200) {content = http.responseText;
- var json=eval('('+content+')');
- return json['access_token'];
- }
- }
- function send_Pic2word_request(img_url_list,access_token){
- host=https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=+access_token+&url=+img_url_list;
- http.open('Post', host, false)
- http.send();
- content = http.responseText;
- WSH.echo(content);
- if (content){
- var json1=eval('('+content+')');
- var n=json1.words_result_num;
- var wr=json1.words_result
- var test1=wr[0].words;
- var test2=wr[1].words;
- var list=test1+'rn'+test2+'rn';
- return list;
- }
- }

