ocrservice
Advanced tools
Comparing version 0.1.33 to 0.1.34
@@ -29,6 +29,13 @@ (function() { | ||
database: db_name, | ||
password: db_password | ||
password: db_password, | ||
connectTimeout: 60000, | ||
acquireTimeout: 60000 | ||
}; | ||
this.limit = 10000; | ||
this.connection = mysql.createConnection(options); | ||
this.connection.on('error', function(err) { | ||
error('DB', err); | ||
return process.exit(); | ||
}); | ||
this.connection.connect(); | ||
} | ||
@@ -35,0 +42,0 @@ |
(function() { | ||
var DB, EventEmitter, Extract, OCR, Recognizer, colorList, contourRanking, cv, lengthRanking, variables, xocr, | ||
var DB, EventEmitter, Extract, OCR, Recognizer, child_process, colorList, contourRanking, cv, lengthRanking, spawn, variables, xocr, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
@@ -18,2 +18,6 @@ hasProp = {}.hasOwnProperty; | ||
child_process = require('child_process'); | ||
spawn = child_process.spawn; | ||
xocr = new OCR(); | ||
@@ -87,29 +91,9 @@ | ||
me = this; | ||
this.brightness = false; | ||
if (typeof brightness === 'undefined') { | ||
brightness = true; | ||
this.brightness = true; | ||
} | ||
this.fileName = fileName; | ||
if (this.fileName) { | ||
return cv.readImage(this.fileName, function(err, im) { | ||
if (err) { | ||
return me.emit('error', err); | ||
} else { | ||
if (im.width() === 0) { | ||
return me.emit('error', 'zero size'); | ||
} else { | ||
im.resize(im.width() * parseFloat(variables.OCR_IMAGE_WIDTH_SCALE), im.height() * parseFloat(variables.OCR_IMAGE_HEIGHT_SCALE)); | ||
me.imageArea = im.width() * im.height(); | ||
me.original = im.clone(); | ||
me.barcode_image = im.clone(); | ||
me.barcode_image.convertGrayscale(); | ||
me.image = im.clone(); | ||
if (brightness === true) { | ||
me.image.brightness(parseFloat(variables.OCR_IMAGE_CONTRAST), parseInt(variables.OCR_IMAGE_BIGHTNESS)); | ||
} | ||
me.image.convertGrayscale(); | ||
me.emit('open', true); | ||
return im = null; | ||
} | ||
} | ||
}); | ||
return cv.readImage(this.fileName, this.imageReaded.bind(this)); | ||
} else { | ||
@@ -120,2 +104,35 @@ return me.emit('error', new Error('there is no image')); | ||
Recognizer.prototype.imageReaded = function(err, im) { | ||
var me; | ||
me = this; | ||
if (err) { | ||
return me.emit('error', err); | ||
} else { | ||
this.im = im; | ||
return this.imageReadedNextTick(); | ||
} | ||
}; | ||
Recognizer.prototype.imageReadedNextTick = function() { | ||
var im, me; | ||
me = this; | ||
im = this.im; | ||
if (im.width() === 0) { | ||
return me.emit('error', 'zero size'); | ||
} else { | ||
im.resize(im.width() * parseFloat(variables.OCR_IMAGE_WIDTH_SCALE), im.height() * parseFloat(variables.OCR_IMAGE_HEIGHT_SCALE)); | ||
me.imageArea = im.width() * im.height(); | ||
me.original = im.clone(); | ||
me.barcode_image = im.clone(); | ||
me.barcode_image.convertGrayscale(); | ||
me.image = im.clone(); | ||
if (this.brightness === true) { | ||
me.image.brightness(parseFloat(variables.OCR_IMAGE_CONTRAST), parseInt(variables.OCR_IMAGE_BIGHTNESS)); | ||
} | ||
me.image.convertGrayscale(); | ||
im = null; | ||
return me.emit('open', true); | ||
} | ||
}; | ||
Recognizer.prototype.removeDoubleRect = function(sorts) { | ||
@@ -217,4 +234,3 @@ var i, lastrect, result; | ||
} | ||
xocr.free(); | ||
return cropped = null; | ||
return xocr.free(); | ||
}; | ||
@@ -258,2 +274,21 @@ | ||
Recognizer.prototype.barcodeOriginal = function(cb) { | ||
var child, codes, me; | ||
me = this; | ||
codes = []; | ||
child = spawn('zbarimg', [this.fileName]); | ||
child.stdout.on('data', function(data) { | ||
var codeparts; | ||
codeparts = data.toString().replace(/\n/, '').split(':'); | ||
if (codeparts.length === 2) { | ||
return codes.push(codeparts[1]); | ||
} | ||
}); | ||
child.stderr.on('data', function(data) {}); | ||
return child.on('exit', function(code) { | ||
me.barcodes = codes; | ||
return cb(codes); | ||
}); | ||
}; | ||
Recognizer.prototype.barcode = function(sep) { | ||
@@ -260,0 +295,0 @@ var codes, im_canny, imagecodes, item, j, k, l, len, len1, len2, sorts; |
@@ -37,3 +37,4 @@ (function() { | ||
Barcode.prototype.action = function(program, options) { | ||
var recognizer; | ||
var fn, recognizer; | ||
console.log('start', Math.round((process.memoryUsage()).rss / 1024)); | ||
recognizer = new Recognizer; | ||
@@ -45,5 +46,30 @@ recognizer.setDebug(program.debug || false); | ||
recognizer.on('open', function(res) { | ||
return console.log(recognizer.barcode()); | ||
var fn; | ||
console.log('after open event', Math.round((process.memoryUsage()).rss / 1024)); | ||
console.log(recognizer.barcode()); | ||
recognizer.barcodeOriginal(function(codes) { | ||
return console.log(codes); | ||
}); | ||
console.log('after barcode', Math.round((process.memoryUsage()).rss / 1024)); | ||
recognizer.free(); | ||
console.log('after free', Math.round((process.memoryUsage()).rss / 1024)); | ||
fn = function() { | ||
console.log('end 10s', Math.round((process.memoryUsage()).rss / 1024)); | ||
return console.log('done'); | ||
}; | ||
process.nextTick(fn); | ||
if (typeof global.gc === 'function') { | ||
return global.gc(); | ||
} | ||
}); | ||
return recognizer.open(options.filename); | ||
fn = function() { | ||
console.log('before open', Math.round((process.memoryUsage()).rss / 1024)); | ||
recognizer.open(options.filename); | ||
return console.log('after open', Math.round((process.memoryUsage()).rss / 1024)); | ||
}; | ||
console.log('before timer', Math.round((process.memoryUsage()).rss / 1024)); | ||
process.nextTick(fn); | ||
if (typeof global.gc === 'function') { | ||
return global.gc(); | ||
} | ||
}; | ||
@@ -50,0 +76,0 @@ |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.1.33", | ||
"version": "0.1.34", | ||
"engines": { | ||
@@ -12,0 +12,0 @@ "node": ">=0.12.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
180784
71
2883
13
3