Why there is a permisson denied error while using node-tesseract-ocr?

Viewed 116

I am using node-tesseract-ocr library for using ocr for my node js project. I installed tesseract-ocr in my machine(windows) using choco and then node-tesseract-ocr using npm. While requesting that particular route I am getting the following error

Error, cannot read input file "myActualPath": Permission denied
Error during processing.

This is the code I am using

const config = {
  lang: 'eng',
  oem: 1,
  psm: 3,
};

    tesseract
      .recognize(__dirname, `../public/data/${reciept}`, config)
      .then((text) => {
        serialResponse = text.match(new RegExp(serial, 'g'));
      })
      .catch((error) => {
        console.log(error.message);
      });
1 Answers

Make sure you have added the tesseract-OCR path in your environment variables, and restart your IDE

Note, for programs like PyCharm and many others, you need to also close the program and re-open it after setting the system environment variable - As told by silas in another post similar to this one. You can refer that post here .

Make sure to import the necessary packages in your module

import pytesseract

import argparse

import cv2

Then construct the argument parser and parse the arguments.

ap = argparse.ArgumentParser()

ap.add_argument("-i", "--image", required=True, help="path to input image to be OCR'd")

args = vars(ap.parse_args())

Note The first Python import you’ll notice in this script is pytesseract (Python Tesseract), a Python binding that ties in directly with the Tesseract OCR application running on your system. The power of pytesseract is our ability to interface with Tesseract rather than relying on ugly os.cmd calls as we needed to do before pytesseract ever existed. For additional reference.

Related