image-node-sdk

1.0.7 • Public • Published

腾讯云 - 智能图像服务

NPM Version Travis Deps

安装

npm i --save image-node-sdk

配置

可以设置以下环境变量,这样就不需要传入 AppId, SecretIDSecretKey 了。

process.env.TENCENTCLOUD_APPID
process.env.TENCENTCLOUD_SECRETID
process.env.TENCENTCLOUD_SECRETKEY
 
// 或
process.env.APPID
process.env.SECRETID
process.env.SECRETKEY

使用

以 OCR-身份证识别 为例,一般支持外链 url 或者本地读取图片文件,两种方式。

  • 外链 url
const {
    ImageClient 
= require('image-node-sdk');
 
let AppId = ''; // 腾讯云 AppId
let SecretId = ''; // 腾讯云 SecretId
let SecretKey = ''; // 腾讯云 SecretKey
 
let idCardImageUrl = 'http://images.cnitblog.com/blog/454646/201306/07090518-029ff26fac014d72a7786937e8319c78.jpg';
let imgClient = new ImageClient({ AppId, SecretId, SecretKey });
imgClient.ocrIdCard({
    data: {
        url_list: [idCardImageUrl]
    }
}).then((result) => {
    console.log(result.body)
}).catch((e) => {
    console.log(e);
});
  • 读取本地文件
const fs = require('fs');
const path = require('path');
const {
    ImageClient 
= require('image-node-sdk');
 
let AppId = ''; // 腾讯云 AppId
let SecretId = ''; // 腾讯云 SecretId
let SecretKey = ''; // 腾讯云 SecretKey
 
let imgClient = new ImageClient({ AppId, SecretId, SecretKey });
imgClient.ocrIdCard({
    formData: {
        card_type: 0,
        image: fs.createReadStream(path.join(__dirname, './idcard.jpg'))
    },
    headers: {
        'content-type': 'multipart/form-data'
    }
}).then((result) => {
    console.log(result.body)
}).catch((e) => {
    console.log(e);
});

如果想运行,example/index.js 下面的例子,请先在项目根目录新建 config/index.js 文件,并按以下格式写下配置

const ProxyUrl = ''; // 可填公司代理
const AppId = ''; // 腾讯云 AppId
const SecretId = ''; // 腾讯云  SecretId
const SecretKey = ''; // 腾讯云 SecretKey
const IdCard = ''; // 身份证号码,用于人脸核身
const Name = ''; // 身份证姓名,用于人脸核身
 
exports.ProxyUrl = ProxyUrl;
exports.AppId = AppId;
exports.SecretId = SecretId;
exports.SecretKey = SecretKey;
exports.IdCard = IdCard;
exports.Name = Name;

然后运行

npm run example

支持功能

更新日志

日志

声明

测试用的身份证源于该文章的实验身份证,如有侵权,请联系作者删除。

Readme

Keywords

none

Package Sidebar

Install

npm i image-node-sdk

Weekly Downloads

9

Version

1.0.7

License

MIT

Unpacked Size

26.7 kB

Total Files

10

Last publish

Collaborators

  • jas0ncn
  • lcxfs1991