Skip to content

Instantly share code, notes, and snippets.

@joemccann
Created January 20, 2013 00:50
Show Gist options
  • Save joemccann/4576069 to your computer and use it in GitHub Desktop.
Save joemccann/4576069 to your computer and use it in GitHub Desktop.
Optical Character Recognition with node.js and Tesseract. Check your console for the results...
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))
@sandrapavankumar
Copy link

sandrapavankumar commented Sep 11, 2018

I changed the path to my local folder image, I face an error something like this, please suggest..

C:\Users\sandrpa\Downloads\nodejs-docs-samples-master\functions\ocr\app>node Test1.js
node-tesseract: Running 'tesseract C:\Users\sandrpa\Downloads\nodejs-docs-samples-master\functions\ocr\app/menu.jpg C:\Users\sandrpa\AppData\Local\Temp\tmp-10948IOynhTcx2Pfo -l eng -psm 6'
node-tesseract: Preprocessor cleanup
{ Error: Command failed: tesseract C:\Users\sandrpa\Downloads\nodejs-docs-samples-master\functions\ocr\app/menu.jpg C:\Users\sandrpa\AppData\Local\Temp\tmp-10948IOynhTcx2Pfo -l eng -psm 6
'tesseract' is not recognized as an internal or external command,
operable program or batch file.

at ChildProcess.exithandler (child_process.js:289:12)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:961:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)

killed: false,
code: 1,
signal: null,
cmd:
'tesseract C:\Users\sandrpa\Downloads\nodejs-docs-samples-master\functions\ocr\app/menu.jpg C:\Users\sandrpa\AppData\Local\Temp\tmp-10948IOynhTcx2Pfo -l eng -psm 6' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment