baidu-ocr-idcard

1.0.5 • Public • Published

baidu-ocr-idcard

基于百度OCR的二代身份证识别,for node

Functionality

扫描第二代身份证,可在回调函数中进一步处理返回数据

Limit

由于基于百度ocr,所以它有什么限制,这就有什么限制。目前比较受影响的限制有:

  • 只支持jpg,且只能上传300KB以内的图片
  • 上传身份证之前请先对身份证上的头像进行模糊处理,否则百度ocr无法识别,深感抱歉。这个问题已经向百度反馈,如果迟迟没有响应,我可能会添加头像模糊处理的功能。

Install

在命令行中输入:

$ npm install baidu-ocr-idcard

Usage

var idcardOCR = require('../lib/baidu-ocr-idcard.js').create('your baidu api key');
    idcardOCR.scan(idcard, side, function(err, data) {
        if(err){
            res.json(err);
            return;
        }
        res.json(data);
    })

API

create

创建一个IDCardOCR对象,需传入百度api key

var idcardOCR = require('../lib/baidu-ocr-idcard.js').create('your baidu api key');

scan

扫描第二代身份证,可在回调函数中进一步处理返回数据。

IDCardOCR.prototype.scan(idcard, side, cb)

idcard为身份证图片的路径,请务必填写正确的图片路径,否则可能造成意想不到的后果。

side为身份证图片的正反面,正面为'obverse',反面为'reverse',其余所有值都为自动识别正反面,不过出于语义化的考虑,建议您填写'auto'

cb为回调函数,它接受两个参数:

idcardOCR.scan(idcard, side, function(err, data) {})

第一个参数是err,第二个参数是data,它们都是PlainObject,格式为{errNum:...,errMsg:...,retData:...}

err:若err存在,则代表出错;不存在,则代表识别成功。errNum一定为-1(Number类型),errMsg有可能为对象或者字符串,retData一定为空字符串''。

dataerrNum一定为0(Number类型),errMsg为字符串,retData的格式分两种情况,正面如下:

{
    name:'string', //姓名
    sex:'string', //性别
    nation:'string', //民族
    birthday:'string', //生日
    residence:'string', //住所
    idNum:'string', //身份证号码
    side:'string' //值为'obverse'
}

反面如下:

{
    authority:'string', //签发机关
    validPeriod:'string', //有效期
    side:'string' //值为'reverse'
}

Examples

运行前请先在根目录使用$ npm install安装依赖,然后$ cd examples$ node index.js,然后在浏览器中输入localhost:8888即可启动。请注意在examples/index.js中相应代码处填写自己的baidu api key,或者添加一个BAIDU_APIKEY环境变量

Test

安装依赖后,在项目根目录输入$ mocha即可。请注意在test/test.js中相应代码处填写自己的baidu api key,或者添加一个BAIDU_APIKEY环境变量

Thanks

百度OCR

百度OCR for node

License

The MIT License (MIT)

Copyright (c) 2015 DophinL

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

/baidu-ocr-idcard/

    Package Sidebar

    Install

    npm i baidu-ocr-idcard

    Weekly Downloads

    6

    Version

    1.0.5

    License

    MIT

    Last publish

    Collaborators

    • dophin