您可以找到我提到的 Tesseract JS Wrapper here .
我们要实现的目标:
- 上传打印文件的照片
- 将那张照片变成文字
到目前为止为设置所做的事情:
npm install tesseract.js
这是我们的代码:
HTML
<input id="myFileInput" type="file" accept="image/*;" capture="camera">
<img id="pic" src="rec.jpg">
JS
<script src="http://tenso.rs/tesseract.js"></script>
<script type="text/javascript">
var img = document.getElementById("pic");
Tesseract
.recognize( img, {
progress: show_progress} )
.then( display )
</script>
控制台中发生了什么:
“未捕获的 ReferenceError:未定义 show_progress”
“你好”,
“主要准备时间:67 毫秒”,
如您所见,我们暂时放弃了照片上传功能,直到我们弄清楚如何让 tesseract.js 为单个预先提供的 jpg 工作。最终,我们希望添加此功能。
任何帮助将不胜感激,我们这样做是为了好玩,主要是寻求一种简单(但有效)的方法来使用 JavaScript 进行 OCR。如果您有其他建议,请告诉我们!
最佳答案
来自 https://github.com/naptha/tesseract.js/blob/a6195ef86d9673cab26120613f53c499b8ec0994/example.htm看来 show_progress 一定是一个函数。
Tesseract.recognize(canvas,{
tessedit_char_blacklist:'e',
progress: function(e){
console.log(e)
}
关于javascript - 将图像传递给 Tesseract.js OCR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36870687/