2

I have this website in which the User Inputs a file and then then the website returns in the console the text in the image. I use Tesseract.js, and the recognize function which has a file as parameter and string for language. Everything works fine when I put a sample file in manually in the function but want to know how to input a file that the users selects. How do I make the user file input in the recognize function? How do I replace "sample.PNG" with the user selected file?

Tesseract.recognize(
    "sample.PNG","eng",
    { 
      logger: m => console.log(m) 
    }
  )
  .catch (err => {
    console.error(err);
  })
  .then(result => {
   console.log(result);
  })
  
  
<html>
<head>
    <script src='https://unpkg.com/tesseract.js@v2.1.0/dist/tesseract.min.js'></script>
 <script src = "script.js"></script>
</head>
<input type="file" name="file" id="fileInput">
<button id = "">Submit</button>
</html>
KhushThakor
  • 112
  • 1
  • 10

0 Answers0