使用Tesseract NPM软件包。并得到以下错误:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of null
我知道UnhandledPromiseRejectionWarning是一个 promise ,会引发错误并且没有
.catch()
方法。这是我的代码(也使用npm sharp软件包)function processText() {
sharp('./screenshot.png')
.extract({ left: 40, top: 585, width: 405, height: 70 })
.resize({ height: 210 })
.toFile(`./text.png`, function (err) {
worker
.recognize('./text.png')
.then(({ text }) => {
console.log(text)
worker.terminate();
})
}
我试过了:
.catch()
方法之后链接.then()
方法这不能解决错误。有什么建议可以消除此错误?
最佳答案
try returning sharp
eg:
function processText() {
return sharp('./screenshot.png')
...
...
}
If you are into ES6 format, check this out
const semiTransparentRedPng = await sharp({
create: {
width: 48,
height: 48,
channels: 4,
background: { r: 255, g: 0, b: 0, alpha: 0.5 }
}
})
.png()
.toBuffer();
Reference: https://www.npmjs.com/package/sharp
关于javascript - TesserActJS错误: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58038433/