Javascript 调整缓冲图像的大小以提高 tesseract OCR 准确性

Javascript resize buffered image to improve tesseract OCR accuracy

如何在传递给 tesseract OCR 之前重新缩放缓冲图像以提高准确性?无论如何都不会实际绘制图像,因为它只是用于处理,所以不确定这是如何完成的。我正在制作一个电子应用程序,但不确定如何以这种方式升级图像。

实际上它不是很准确,因为我需要处理的图像非常小。

const image = 'image.png';
tesser(image);

function tesser(image) {
  Tesseract.recognize(image)
  .then(function(result){
      console.log(result.text)
  })
}

既然没人回答我就post我最后找到的。我可以使用 Sharp 库调整缓冲图像的大小。

img.onload = resizeImg;
img.src = 'image.png';

function resizeImg() {
  this.path = this.path = 'image.png';

  sharp(this.path)
  .resize(this.width * 2, this.height * 2)
  .toBuffer({ resolveWithObject: true })
  .then(({ data, info }) => {
      //process data
  })
}