Created
July 30, 2018 20:12
-
-
Save murilohns/4d3e7d2748fd1d953e5d3a601717c4ea to your computer and use it in GitHub Desktop.
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
const Promise = require('bluebird') | |
const Tesseract = require('tesseract.js') | |
const Jimp = require('jimp') | |
const { promisify } = require('util') | |
const url = 'https://i.imgur.com/dPJ8py9.png' | |
const getImage = async (url, scale = 1) => { | |
return await Jimp.read(url) | |
.then( async image => { | |
let resizedImage = await image.scale(scale); | |
return await new Promise((resolve, reject) => { | |
resizedImage.getBuffer(Jimp.MIME_PNG, (err, data) => { | |
resolve(getImageText(data)) | |
}) | |
}) | |
}) | |
} | |
const getImageText = async (image) => { | |
const imageText = await Tesseract.recognize(image, { | |
lang: 'por', | |
//textord_restore_underlines: 5, | |
//tessedit_char_whitelist: ['_'] | |
}) | |
return imageText.text | |
//console.log(imageText.text); | |
} | |
Promise.all([getImage(url), getImage(url, 2.5)]) | |
.then((imagesText) => { | |
imagesText.map(text => { | |
console.log(text) | |
}) | |
}) | |
vagrantsn
commented
Jul 30, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment