Skip to content

Instantly share code, notes, and snippets.

@kolarski
Last active May 4, 2019 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolarski/0bc2a3feb02adb1b63016d0d78b3653c to your computer and use it in GitHub Desktop.
Save kolarski/0bc2a3feb02adb1b63016d0d78b3653c to your computer and use it in GitHub Desktop.
Tesseract
<html>
<html>
<head>
<title>Tesseract-JS Demo</title>
</head>
<body>
<input type="text" id="url" placeholder="Image URL" />
<!--<div id="ocr_results"> </div>-->
<div id="ocr_status"> </div>
<div>
<label>Filed1
<label>
<textarea id="txt" ></textarea>
</div>
</body>
<script src='https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
function runOCR(url) {
Tesseract.recognize(url)
.then(function(result) {
document.getElementById("txt")
.innerHTML = result.text;
document.getElementById('txt').focus();
}).progress(function(result) {
document.getElementById("ocr_status")
.innerText = result["status"] + " (" +
(result["progress"] * 100) + "%)";
});
}
document.getElementById("url")
.addEventListener("change", function(e) {
var url = document.getElementById("url").value;
runOCR(url);
});
const urlParams = new URLSearchParams(window.location.search);
const myImage = urlParams.get('image');
if (myImage) {
runOCR(myImage);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment