User:Alexander Roidl/WebOCR

From XPUB & Lens-Based wiki

Web OCR

Scan-test-text-855.jpg
Screen Shot 2018-01-28 at 20.52.14.png


Libraries

I tried the OCRAD JS

http://antimatter15.com/ocrad.js/demo.html

and the tesseract JS

Tesseract.js


Tesseract JS

Insert the library

<script src="https://cdn.rawgit.com/naptha/tesseract.js/0.2.0/dist/tesseract.js"></script>

main function

<script>
function runOCR(url) {
    Tesseract.recognize(url)
         .then(function(result) {
            document.getElementById("ocr_results")
                    .innerText = result.text;
         }).progress(function(result) {
            document.getElementById("ocr_status")
                    .innerText = result["status"] + " (" +
                        (result["progress"] * 100) + "%)";
        });
}

document.getElementById("go_button")
        .addEventListener("click", function(e) {
            var url = document.getElementById("url").value;
            runOCR(url);
        });

</script>