public
Created

Optical Character Recognition with node.js and Tesseract. Check your console for the results...

  • Download Gist
ocr.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
var ncr = require('nodecr')
, request = require('request')
, fs = require('fs')
, test_img = 'https://www.google.com/images/srpr/logo3w.png' // Change this to your image
// Create image name from end of URL.
// Note this will fail in loads of cases.
var imgName = test_img.split('/').pop()
 
// Process the image and read the text from it using Tesseract
function ncrHandler(){
 
ncr.process(__dirname + '/' + imgName,function(err, text){
 
if(err) return console.error(err)
 
console.log("Here is the text: \n")
console.log(text)
 
}, 'eng', 6)
}
 
// Fetch the image, pipe it to a writeable stream and then fire
// ncrHandler...
request(test_img, ncrHandler).pipe(fs.createWriteStream(imgName))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.