NODE-百度AI OCR识别

福尔摩斯对我笑 2019-01-25 22351 次 9072条

申请KEY,下载SDK,安装baidu-aip-sdk模块;详细文档地址及KEY申请地址 http://ai.baidu.com/docs#/Auth/top

var AipOcrClient = require("baidu-aip-sdk").ocr;

// 设置APPID/AK/SK
var APP_;
var API_KEY = "your key";
var SECRET_KEY = "you secret_key";

// 新建一个对象,建议只保存一个对象调用服务接口
var client = new AipOcrClient(APP_ID, API_KEY, SECRET_KEY);

// console.log(client)


var fs = require('fs');

var image = fs.readFileSync("2.jpg").toString("base64");

// 调用通用文字识别(高精度版)
client.accurateBasic(image).then(function(result) {
    console.log(JSON.stringify(result));
}).catch(function(err) {
    // 如果发生网络错误
    console.log(err);
});


// 如果有可选参数
// var options = {};
// options["detect_direction"] = "true";
// options["probability"] = "true";

// // 带参数调用通用文字识别(高精度版) 识别更为精准,当然,耗时也长一点
// client.accurateBasic(image, options).then(function(result) {
//     console.log(JSON.stringify(result));
// }).catch(function(err) {
//     // 如果发生网络错误
//     console.log(err);
// });;
var AipOcrClient = require("baidu-aip-sdk").ocr;

// 设置APPID/AK/SK
var APP_;
var API_KEY = "XMYKiMOFM3LBkXf4OUcT0nYc";
var SECRET_KEY = "2RiBlgFhpGWty590LFbLlAwqPX4itRBN";

// 新建一个对象,建议只保存一个对象调用服务接口
var client = new AipOcrClient(APP_ID, API_KEY, SECRET_KEY);

// console.log(client)


var fs = require('fs');

var image = fs.readFileSync("2.jpg").toString("base64");

// 调用通用文字识别, 图片参数为本地图片
client.generalBasic(image).then(function(result) {
    console.log(JSON.stringify(result));
}).catch(function(err) {
    // 如果发生网络错误
    console.log(err);
});

// // 如果有可选参数
// var options = {};
// var options = {};
// options["language_type"] = "CHN_ENG";
// options["detect_direction"] = "true";
// options["detect_language"] = "true";
// options["probability"] = "true";

// // 带参数调用通用文字识别, 图片参数为本地图片
// client.generalBasic(image, options).then(function(result) {
//     console.log(JSON.stringify(result));
// }).catch(function(err) {
//     // 如果发生网络错误
//     console.log(err);
// });;

// var url = "https//www.x.com/sample.jpg";

// // 调用通用文字识别, 图片参数为远程url图片
// client.generalBasicUrl(url).then(function(result) {
//     console.log(JSON.stringify(result));
// }).catch(function(err) {
//     // 如果发生网络错误
//     console.log(err);
// });

// // 如果有可选参数
// var options = {};
// options["language_type"] = "CHN_ENG";
// options["detect_direction"] = "true";
// options["detect_language"] = "true";
// options["probability"] = "true";

// // 带参数调用通用文字识别, 图片参数为远程url图片
// client.generalBasicUrl(url, options).then(function(result) {
//     console.log(JSON.stringify(result));
// }).catch(function(err) {
//     // 如果发生网络错误
//     console.log(err);
// });;
标签:

非特殊说明,本博所有文章均为博主原创。

头像也是LOGO
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 9072 条评论 1


  1. kyrie 3

    I just wanted to develop a quick note in order to thank you for these lovely advice you are giving here. My time consuming internet investigation has finally been rewarded with good quality knowledge to share with my co-workers. I ‘d mention that most of us site visitors are unquestionably fortunate to be in a remarkable community with many outstanding professionals with very beneficial tips and hints. I feel very much lucky to have seen your web pages and look forward to so many more fun moments reading here. Thanks again for all the details.

    回复 2019年10月10日
  2. yeezy boost 350 v2

    My husband and i ended up being really excited Chris could finish up his investigation from the ideas he obtained from your very own web page. It is now and again perplexing to just choose to be freely giving ideas which usually some others have been trying to sell. And we also remember we have got the writer to thank because of that. The explanations you made, the simple website menu, the friendships you will make it possible to promote – it’s got many amazing, and it’s facilitating our son in addition to the family consider that that topic is brilliant, which is extraordinarily serious. Thank you for all the pieces!

    回复 2019年10月9日
  3. kyrie irving shoes

    I and also my buddies ended up examining the nice procedures found on your site and so the sudden I had an awful feeling I never thanked the blog owner for those secrets. These young boys had been for this reason thrilled to learn them and have in effect absolutely been taking advantage of those things. Appreciate your truly being really thoughtful and for deciding on such useful tips most people are really needing to discover. My personal sincere regret for not expressing appreciation to earlier.

    回复 2019年10月9日
  4. adidas tubular

    I’m also commenting to make you be aware of what a cool encounter my princess had going through your webblog. She noticed several pieces, which included what it’s like to possess an ideal coaching nature to make many more without difficulty learn certain tricky matters. You undoubtedly did more than visitors’ expectations. I appreciate you for showing such insightful, trustworthy, educational not to mention cool thoughts on that topic to Gloria.

    回复 2019年10月8日
  5. 奥巴马

    写的还可以

    回复 2019年4月4日
  6. 好好

    回复 2019年3月19日
  7. 陈先生

    能分享源码吗

    回复 2019年3月16日
  8. jie

    6666

    回复 2019年3月14日
  9. 白子

    路过~我买的酸酸菌#^_^#
    发现一枚技术大佬啊~

    回复 2019年3月7日
  10. 1

    厉害

    回复 2019年3月6日
  11. 秦兽兽

    哪里来的模板呢

    回复 2019年3月6日