0

How can I rescale a buffered image before passing to tesseract OCR for improved accuracy? The image won't be actually drawn anyway since it's just for processing so not sure how this is done. I'm making an electron app and not sure how to upscale the image in this way.

As it is it isn't very accurate as the images I need to process are very small.

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

function tesser(image) {
  Tesseract.recognize(image)
  .then(function(result){
      console.log(result.text)
  })
}
Hasen
  • 11,710
  • 23
  • 77
  • 135
  • Is this https://stackoverflow.com/questions/19262141/resize-image-with-javascript-canvas-smoothly helpful? – Claudio May 04 '19 at 15:34
  • @Claudio It doesn't have an elemend ID of `canvas` since it's not displayed anywhere, The image is stored in the buffer only. – Hasen May 05 '19 at 05:40

1 Answers1

0

Since no-one answered I will post what I found in the end. I could achieve resizing a buffered image using the lib 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
  })
}
Hasen
  • 11,710
  • 23
  • 77
  • 135