【问题标题】:tesseract.js sample code not workingtesseract.js 示例代码不起作用
【发布时间】:2016-11-17 17:56:06
【问题描述】:

我正在尝试让 Tesseract.js 工作。

我从网上获取了一个非常简单的代码,显然声明它可以工作,但它没有。

<html>
    <head>
        <script src='https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js'></script>
        <title>Tesseract Test</title>
    </head>
    <body>
        <label for="fileInput">Choose File to OCR:</label>
        <input type="file" id="fileInput" name="fileInput"/>
        <br />
        <br />
        <div id="document-content">
        </div>
    </body>
    <script>
        document.addEventListener('DOMContentLoaded', function(){
            var fileInput = document.getElementById('fileInput');
            fileInput.addEventListener('change', handleInputChange);
        });

        function handleInputChange(event){
            var input = event.target;
            var file = input.files[0];
            console.log(file);
            Tesseract.recognize(file)
                .progress(function(message){
                    console.log(message);
                })
                .then(function(result){
                    var contentArea = document.getElementById('document-content');
                    console.log(result);
                })
                .catch(function(err){
                    console.error(err);
                });
        }
    </script>
</html>

这是他们的主要网站:http://tesseract.projectnaptha.com/

【问题讨论】:

    标签: javascript ocr tesseract


    【解决方案1】:

    对我有用,但我必须做出这个改变:

    .then(function(result) {
      var contentArea = document.getElementById('document-content');
      contentArea.innerHTML = result.text;
    })
    

    (您发布的示例仅记录到控制台。)

    【讨论】:

    • 由于某些原因,我在记录控制台时遇到问题,但它可以在 contentArea 中显示内容。谢谢
    • 另外,你知道为什么它只能在 Firefox 上运行,而不能在 explorer 或 chrome 上运行吗?
    • 这是我的小提琴:jsfiddle.net/khrismuc/8aL31upr 在 Chrome 54 和 IE 11 中运行良好。您检查控制台了吗?
    • 大多数时候我得到这个错误:Uncaught DataCloneError: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': An object could not be cloned.
    • 第一次运行时,脚本要下载几个大资源文件。只需清除缓存并在 tesseract 页面上观看演示,您将看到几个条形图显示各种内容的加载方式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 2017-02-19
    相关资源
    最近更新 更多