Tesseract.js offline:ReferenceError:未定义Tesseract

时间:2018-01-13 19:51:55

标签: javascript firefox localhost tesseract tesseract.js

我创建了一个本地网页,我将使用默认的Tesseract.js(复制自CDN tesseract.js,worker.js,eng.traineddata.gz,index.js)。 这是我使用的代码:

在头上:

<script scr="js/tesseract.js"></script>
<script>
    //Set the worker, core and lang to local files
    (function() {
    var path = (function() { //absolute path
    var pathArray = window.location.pathname.split( '/' );
    pathArray.pop(); //Remove the last ("**.html")
    return window.location.origin + pathArray.join("/");
    })();
    console.log(path);

    window.Tesseract = Tesseract.create({
    workerPath: path + '/js/worker.js',
    langPath: path + '/js/eng.traineddata.gz',
    corePath: path + '/js/index.js'
    });
    })();
</script>

按钮上运行的代码:

var img = document.getElementById('UploadAndPreview');
    Tesseract.recognize(img)
    .progress(function(result) {
            document.getElementById("ocr_status")
                    .innerText = result["status"] + " (" +
                        (result["progress"] * 100) + "%)";
    })
    .then(function(result){
        console.log('Something is going on');
        console.log(result);
    })

在浏览器中本地打开页面后,出现错误:

ReferenceError: Tesseract is not defined

如何解决这个问题?

0 个答案:

没有答案