npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

baidu-ocr-idcard

v1.0.5

Published

基于百度ocr的二代身份证识别

Downloads

8

Readme

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.