Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to extract text from image using javascript

<script src="./tesseract.js"></script>
<script>
  // 1. After including the Tesseract script, initialize it in the browser
  // Note: to prevent problems while tesseract loads scripts, provide the absolute path to the file from your domain
  window.Tesseract = Tesseract.create({
  // Path to worker
  workerPath: 'http://mydomain.com/worker.js',
  // Path of folder where the language trained data is located
  // note the "/" at the end, this string will be concatenated with the selected language
  langPath: 'http://mydomain.com/langs-folder/',
  // Path to index script of the tesseract core ! https://github.com/naptha/tesseract.js-core
  corePath: 'http://mydomain.com/index.js',
  });

  // 2. Write some logic to initialize the text recognition
  document.getElementById("img-to-txt").addEventListener("click", function(){
  let btn = this;

  // Disable button until the text recognition finishes
  btn.disable = true;

  // Convert an image to text. This task works asynchronously, so you may show
  // your user a loading dialog or something like that, or show the progress with Tesseract
  Tesseract.recognize("./text.png").then(function(result){
  // The result object of a text recognition contains detailed data about all the text
  // recognized in the image, words are grouped by arrays etc
  console.log(result);

  // Show recognized text in the browser !
  alert(result.text);
  }).finally(function(){
  // Enable button once the text recognition finishes (either if fails or not)
  btn.disable = false;
  });
  }, false);
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: json concat 
Javascript :: How to change height of bottom material tab navigator from react-naviagtion 
Javascript :: react-router in saga 
Javascript :: javascript copy clipboard 
Javascript :: axios get array of urls 
Javascript :: useParams 
Javascript :: set a variable in express.js 
Javascript :: one line if statement javascript 
Javascript :: trim text 
Javascript :: add another column without delete table sequelize 
Javascript :: React Native drawer navigation screen header title and buttons 
Javascript :: upload photos cypress 
Javascript :: pass props in react 
Javascript :: react native paper textinput 
Javascript :: mapbox add a leaflet marker with popup 
Javascript :: how to decode jwt token in react 
Javascript :: javscript loop array 
Javascript :: unknown provider angularjs 
Javascript :: react validation form 
Javascript :: send response from iframe to parent 
Javascript :: javascript eventlistener 
Javascript :: inline style to change background color javascript 
Javascript :: how to draw circle in javascript 
Javascript :: Don’t Use If-Else and Switch in JavaScript, Use Object Literals 
Javascript :: sequelize transaction 
Javascript :: packages.json from file 
Javascript :: how to update react app 
Javascript :: ajax returning html instead of json 
Javascript :: This function is used to store items in local storage 
Javascript :: confirm alert 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =