Created
January 20, 2013 00:50
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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' }