const Vision = require('@google-cloud/vision');
// Instantiates a client
const vision = Vision({
languageHints: [ "en", "zh-TW", "zh-CN" ], //要辨識的語言
keyFilename:'./01.json'
});
// The path to the local image file, e.g. "/path/to/image.png"
// const fileName = '/path/to/image.png';
// Performs text detection on the local file
vision.detectText('./0.jpg')
.then((results) => {
const detections = results[0];
console.log('Text:');
detections.forEach((text) => console.log(text));
});
Open Source可用模組
上面的連結是下面tesseract的Node.js wrapper
範例程式如下
var tesseract = require('node-tesseract');
var options = {
l: 'chi_tra',
psm: 6,
binary: '/usr/local/bin/tesseract'
};
// Recognize text of any language in any format
tesseract.process(__dirname + '/022.png', options,function(err, text) {
if(err) {
console.error(err);
} else {
console.log(text);
}
});