v0.0.3 use jsqr

This commit is contained in:
cnwhy
2018-07-30 21:11:42 +08:00
parent 2e142c20e8
commit 14edfc7fbb
8 changed files with 113 additions and 18 deletions
+6 -2
View File
@@ -3,7 +3,11 @@ var Decoder = require('./lib/Decoder');
var debug = false;
// 获取指定位置的灰度
/**
* 返回获取指定位置的灰度的函数
* @param {ImageData} data
* @param {Object} base 一个有width,height信息
*/
var Pixel = function (data,base) {
return function(x,y){
if (base.width < x || base.height < y) {
@@ -16,7 +20,7 @@ var Pixel = function (data,base) {
var binarize = function(data,base,th){
var ret = new Array(base.width * base.height);
var getPixel = Pixel(data,base);
var getPixel = Pixel(data,base); //
for (var y = 0; y < base.height; y++) {
for (var x = 0; x < base.width; x++) {
var gray = getPixel(x, y);
+4
View File
@@ -0,0 +1,4 @@
var jsqr = require('jsqr');
module.exports = function(imageData){
return jsqr(imageData.data,imageData.width,imageData.height).data;
}
+2 -2
View File
@@ -32,8 +32,8 @@ Decoder.correctErrors = function (codewordBytes, numDataCodewords) {
Decoder.decode = function (bits) {
var parser = new BitMatrixParser(bits);
var version = parser.readVersion();
var ecLevel = parser.readFormatInformation().ErrorCorrectionLevel;
var version = parser.readVersion(); //版本信息
var ecLevel = parser.readFormatInformation().ErrorCorrectionLevel; //格式信息
// Read codewords
var codewords = parser.readCodewords();